Suppose I have a 3*3*3
array x
. I would like to find out an array y
, such that such that y[0,1,2] = x[1,2,0]
, or more generally, y[a,b,c]= x[b,c,a]
. I can try numpy.transpose
import numpy as np
x = np.arange(27).reshape((3,3,3))
y = np.transpose(x, [2,0,1])
print(x[0,1,2],x[1,2,0])
print(y[0,1,2])
The output is
5 15
15
The result 15,15
is what I expected (the first 15
is the reference value from x[1,2,0]
; the second is from y[0,1,2]
) . However, I found the transpose [2,0,1]
by drawing in a paper.
B C A
A B C
by inspection, the transpose should be [2,0,1]
, the last entry in the upper row goes to 1st in the lower row; the middle goes last; the first go middle. Is there any automatic and hopefully efficient way to do it (like any standard function in numpy/sympy)?
Given the input y[a,b,c]= x[b,c,a]
, output [2,0,1]
?