I have a 3-D NumPy array, e.g.
a = np.random.random((2,3,5))
I would like to transpose the last two axes, i.e.
b = a.transpose(0,2,1)
However, I do not want a view with twiddled strides! I want to actually copy the array and reorder it in memory. What is the best way to achieve this?
b = np.zeros((2,5,3)); b[:] = a.transpose(0,2,1)
, but yours is much cleaner. – Censor