When I have a=1 and b=2, I can write a,b=b,a so that a and b are interchanged with each other.
a=1
b=2
a,b=b,a
a
b
I use
A very simple solution would be to use swapaxes
x = x.swapaxes(1,2)