Thanks, this is exactly what I was looking for! Out of curiosity, why is it that the extra dimension is added to the middle, so it becomes (5, 1, 3)?
Lastly, a follow-up question, is it possible to apply this batchwise, so if you had for example:
a = torch.randn(1, 5, 3)
b = torch.randn(1, 5, 3)

What seems to be working is just doing res = a.unsqueeze(2) - b, but I’m not sure if that’s 100% correct (although the values match with both methods when I use two fixed arrays).