Multiplication by scalar adds unneeded dimension to tensor

Hi

I have the following code:

#c is a tensor of shape [1,1]
a = torch.zeros([3])
#here a.shape is [3]
a = c * a
#here a.shape is [1, 3]

I want a result of shape [3].

How can I achieve a result of shape [3]?

Thanks

a = c.squeeze() * a

or

a = (c * a).squeeze()
1 Like