2012-10-08 40 views
19

我正在将一个程序从matlab翻译成Python。python中的“排列”

的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