1.expand_as()函数
expand_as
将张量扩展为参数tensor的大小。
>>> x = torch.randn(1, 3, 1, 1)
>>> y = torch.randn(1, 3, 3, 3)
>>> z = x.expand_as(y)
>>> print(x)
tensor([[[[ 0.4383]],
[[-1.5909]],
[[ 0.0814]]]])
>>> print(z)
tensor([[[[ 0.4383, 0.4383, 0.4383],
[ 0.4383, 0.4383, 0.4383],
[ 0.4383, 0.4383, 0.4383]],
[[-1.5909, -1.5909, -1.5909],
[-1.5909, -1.5909, -1.5909],
[-1.5909, -1.5909, -1.5909]],
[[ 0.0814, 0.0814, 0.0814],
[ 0.0814, 0.0814, 0.0814],
[ 0.0814, 0.0814, 0.0814]]]])