2012-10-08 19 views
19

私はmatlabからPythonに翻訳しています。matlabの "permute" in python

MathWorks社のMATLABコードは、メソッドを使用して並び替える:

B = PERMUTE(A,ORDER) rearranges the dimensions of A so that they 
% are in the order specified by the vector ORDER. The array produced 
% has the same values as A but the order of the subscripts needed to 
% access any particular element are rearranged as specified by ORDER. 
% For an N-D array A, numel(ORDER)>=ndims(A). All the elements of 
% ORDER must be unique. 

は、Python/numpyので同等の方法はありますか?

+0

[numpy.rollaxis](http://docs.scipy.org/doc/numpy/reference/generated/numpy.rollaxis.html#numpy.rollaxis)は近いです... – mgilson

+2

@Mauritsこれはランダムな順列です。 Matlabの関数 "permute"の記述にランダムなことは何もないので、ランダムでないと仮定します。 – LynnH

+0

@ user1729698私の間違いです。 – Maurits

答えて

22

これは、transposeの機能にロールバックされ、numpy.ndarrayになります。デフォルトの動作では順序が逆になりますが、独自の順序のリストを指定できます。

+0

ありがとう、これは確かに解決策でした:) – LynnH