Maybe this is a silly question, but how can we sum over multiple dimensions in pytorch?
In numpy, np.sum()
takes a axis
argument which can be an int or a tuple of ints, while in pytorch, torch.sum()
takes a dim
argument which can take only a single int.
Say I have a tensor of size 16 x 256 x 14 x 14
, and I want to sum over the third and fourth dimensions to get a tensor of size 16 x 256
. In numpy, one can do np.sum(t, axis=(2, 3))
, what is the pytorch equivalent?