permuteVector

Rearranges the elements of a vector as specified by a permutation.

Synopsis

permuteVector (x, permutation, permute)

Required Arguments

float x[] (Input)
Array of length nElements to be permuted.
int permutation[] (Input)
Array of length nElements containing the permutation.
Imsls_permute permute (Input)
Keyword of type Imsls_permute. Argument permute must be either FORWARD_PERMUTATION or BACKWARD_PERMUTATION. If FORWARD_PERMUTATION is specified, then a forward permutation is performed, i.e., x[permutation[i]] is moved to location i in the return vector. If BACKWARD_PERMUTATION is specified, then a backward permutation is performed, i.e., x[i] is moved to location permutation[i] in the return vector.

Return Value

An array of length nElements containing the input vector x permuted.

Description

Function permuteVector rearranges the elements of a vector according to a permutation vector. The function can perform both forward and backward permutation.

Example

This example rearranges the vector x using permutation. A forward permutation is performed.

from pyimsl.stat.permuteVector import permuteVector, FORWARD_PERMUTATION
from pyimsl.stat.writeMatrix import writeMatrix

x = [5.0, 6.0, 1.0, 4.0]
permutation = [2, 0, 3, 1]

output = permuteVector(x, permutation, FORWARD_PERMUTATION)

writeMatrix("permuted result", output, colNumberZero=True)

Output

 
                  permuted result
          0            1            2            3
          1            5            4            6