Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matlab's "permute" in python

Tags:

I'm translating a program from matlab to Python.

The matlab code uses the method permute:

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. 

Is there an equivalent method in Python/NumPy ?

like image 325
LynnH Avatar asked Oct 08 '12 18:10

LynnH


People also ask

How do you Permute in Matlab?

B = permute( A , dimorder ) rearranges the dimensions of an array in the order specified by the vector dimorder . For example, permute(A,[2 1]) switches the row and column dimensions of a matrix A . In general, the ith dimension of the output array is the dimension dimorder(i) from the input array.

How do you generate random permutations in Python?

To generate random Permutation in Python, then you can use the np random permutation. If the provided parameter is a multi-dimensional array, it is only shuffled along with its first index. If the parameter is an integer, randomly permute np.

How do you Permute a vector in Matlab?

P = perms( v ) returns a matrix containing all permutations of the elements of vector v in reverse lexicographic order. Each row of P contains a different permutation of the n elements in v . Matrix P has the same data type as v , and it has n! rows and n columns.

What is the permute () function in Python?

The permute () function rearranges the dimensions of the specified array in the order specified by the vector dimorder. Parameters: This function accepts two parameters, which are illustrated below:

How do I permute an array in MATLAB?

MATLAB includes a function called permute (), which is a generalization of the transpose function but for ND arrays. Permute () takes in an ND-array and the desired array order and then returns the rearranged data. The syntax looks this: newArray = permute ( oldArray, [oldDim1, oldDim2, oldIm3, etc…] ).

How do you do a recursive permutation in Python?

Permutations in Python 1 We will use the recursive approach, this will make the list, start, curr and res 2 if start > length of list – 1, then add curr into the res, and return 3 for i in range start to length of given list – 1 swap the elements of list present at index start and (start + (i – start)) permutation (list, start ...

What is the difference between ipermute and permute in MATLAB?

The output of permuting is always transposed of the output of permute and output of permuting is always transposed of the output of ipermute. Below is the syntax for Permute Matlab:


1 Answers

This is rolled into the transpose function in numpy.ndarray. The default behavior reverses the order, but you can supply a list of your own order.

like image 76
aganders3 Avatar answered Sep 20 '22 04:09

aganders3