x= x.sum(-2) works also with my code.
I got the below error if I choose a value  not between [-2,1]
IndexError: Dimension out of range (expected to be in range of [-2, 1], but got 3)

And the below error with dimension =1
RuntimeError: mat1 and mat2 shapes cannot be multiplied (1x8 and 16384x1)

How can I solve that?