Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
matlab';s";“排列”;用python_Python_Matlab - Fatal编程技术网

matlab';s";“排列”;用python

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

我正在把一个程序从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 
%   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,:]
的东西,这取决于你想要新轴的位置。如果需要,可以在此之后转置轴。