2

I got a 3D tensor three and a 2D tensor two, which need to be multiplied. For example, the dimensions are:

three.shape = 4x100x700 two.shape = 4x100 

Output shape should be:

output.shape = 4x100x700 

So basically, in output[a,b] there should be 700 scalars which were computed by multiplying all 700 scalars from three[a,b] with the single scalar from two[a,b].

1 Answer 1

3

You can simply add an extra dimension to two:

output = three * two.unsqueeze(-1) 

There are alternative syntax, e.g.:

output = three * two[..., None] 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.