naginterfaces.library.sort.permute_​invert

naginterfaces.library.sort.permute_invert(iperm, m1)[source]

permute_invert inverts a permutation, and hence converts a rank vector to an index vector, or vice versa.

For full information please refer to the NAG Library document for m01za

https://support.nag.com/numeric/nl/nagdoc_30.1/flhtml/m01/m01zaf.html

Parameters
ipermint, array-like, shape

Elements to of must contain a permutation of the integers to .

m1int

Note: this argument represents an array index; the value you supply must be base-1 for compatibility with the NAG Engine.

and must specify the range of elements used in the array and the range of values in the permutation, as specified under .

Returns
ipermint, ndarray, shape

These elements contain the inverse permutation of the integers to .

Raises
NagValueError
(errno )

On entry, and .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

does not contain a permutation of the integers to . contains an out-of-range value: , .

(errno )

does not contain a permutation of the integers to . contains a repeated value: .

Notes

In the NAG Library the traditional C interface for this routine uses a different algorithmic base. Please contact NAG if you have any questions about compatibility.

There are two common ways of describing a permutation using an integer vector . The first uses ranks: holds the position to which the th data element should be moved in order to sort the data; in other words its rank in the sorted order. The second uses indices: holds the current position of the data element which would occur in th position in sorted order. For example, given the values

to be sorted in ascending order, the ranks would be

and the indices would be

The functions realvec_rank(), intvec_rank(), charvec_rank(), realmat_rank_rows(), intmat_rank_rows(), realmat_rank_columns(), intmat_rank_columns() and arbitrary_rank() generate ranks, and the functions realvec_rank_rearrange(), intvec_rank_rearrange(), charvec_rank_rearrange() and cmplxvec_rank_rearrange() require ranks to be supplied to specify the reordering. However if it is desired simply to refer to the data in sorted order without actually reordering them, indices are more convenient than ranks.

permute_invert can be used to convert ranks to indices, or indices to ranks, as the two permutations are inverses of each another.