matlab';s";“排列”;用python
我正在把一个程序从matlab翻译成Python matlab代码使用以下方法排列:matlab';s";“排列”;用python,python,matlab,Python,Matlab,我正在把一个程序从matlab翻译成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
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中是否有等效的方法?这将被放入
NumPy.ndarray
中的函数中。默认行为会颠倒顺序,但您可以提供自己顺序的列表。接近…@Maurits这是随机排列。因为在matlab中对函数“permute”的描述中没有关于随机的内容,所以我假设它不是随机的…@user1729698我的错误。但是如果我有一个大小为[4,6]的数组,并且我想使它成为[1,4,6],该怎么办呢。在MATLAB中,它将是mX=permute(mA,[3,1,2])代码>。然而Python中的transpose
无法做到这一点(因为数组的形状没有第三维)。如果你想添加一个轴,我会使用类似于a=a[np.newaxis,…]
或a=a[:,np.newaxis,:]
的东西,这取决于你想要新轴的位置。如果需要,可以在此之后转置轴。