Tensor.expand_as 1

Tensor.expand_as

a = torch.rand(2, 3)
b = torch.rand(2,2, 3)
print('a:',a)
print('b:',b)
c = a.expand_as(b)
print('c:',c)

Here is what the above code is Doing:
1. a is a 2×3 tensor
2. b is a 2x2x3 tensor
3. c is a 2x2x3 tensor
4. a.expand_as(b) expands the tensor a to the shape of b
5. c is now a 2x2x3 tensor with the same values as a

Similar Posts