(Torch tenor) Subtracting different dimension matrices
matrice1 = temp.unsqueeze(0)  
print(M.shape)
matrice2 = M.permute(1, 0, 2, 3)
print(matrice2.shape)
print( torch.abs(matrice1 - matrice2).shape )


#torch.Size([1, 10, 3, 256])
#torch.Size([10, 1, 3, 256])
#torch.Size([10, 10, 3, 256])

I got the outcome above. I am wondering why the subtraction between two different dimension tensors make the outcome the tensor that has the shape as [10,10,3,256].

According to the broadcast semantics of PyTorch,The two tensors are &quot;broadcastable&quot; in your case, so they are automatically expanded to the equal size of torch.Size([10, 10, 3, 256]).
