what is an equivalent of matlab permute(A, [3 2 1]) in python? what is an equivalent of matlab permute(A, [3 2 1]) in python? numpy numpy

what is an equivalent of matlab permute(A, [3 2 1]) in python?


You are looking for numpy.transpose

np.transpose( np.expand_dims(A, axis=2), (2, 1, 0) )

Since numpy does not have trailing Singleton dimensions by default, you need to explicitly add it using np.expand_dims

Or else a shorthand for np.expand_dims(A, axis=2) is A[:, :, None] so

np.transpose(A[:, :, None], (2,1,0))