1
votes

I have two PyTorch tensors A with shape [30, 11, 32, 64] and B with shape [30, 11, 89]. My goal is to create a tensor C with shape [30, 11, 89, 32, 64] where the tensor A should be extended and replicated in the third dimension and then be multiplied with tensor B at the appropriate dimensions.

How can this be accomplished in PyTorch?

1

1 Answers

0
votes

You can use broadcasting semantics the same as numpy. One way to accomplish this is

C = A.reshape(30, 11, 1, 32, 64) * B.reshape(30, 11, 89, 1, 1)