Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

If A is a 2x2 array, what is an equivalent expression in python for permute(A, [3 2 1]) in MATLAB?

Thank you

like image 632
user4279562 Avatar asked Jan 15 '15 18:01

user4279562


1 Answers

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))
like image 184
Shai Avatar answered Oct 02 '22 08:10

Shai