I am very new to coding + pytorch
I have an input tensor torch.full((row,col), 2.0), called A
and I want to have an output looks like [[2,2,2], [4,4,4], [6,6,6], …], called B
The idea is to multiple A and B, pytorch will do broadcasting for me if I understand correctly.
So I tried:
r, c = A.size()
x = torch.arange( r ) + 1.0
the x has shape ‘torch.Size([4])’, it seems like not broadcastable, which means A*x reports error.
I tried a little experiment, y = torch.randn(4,1). Then A*y is ok. So I think this is because x has shape [4] and y has shape [4,1]. I tried to change x’s shape to [4,1] using x.view(4,1). But it didn’t work. The shape of x is still [4]. Could anyone help me on this? Thank you a lot for your time!