permuteMatrix¶
Permutes the rows or columns of a matrix.
Synopsis¶
permuteMatrix (a, permutation, permute)
Required Arguments¶
- float
a[[]]
(Input) - Matrix of size
nRows
×nColumns
to be permuted. - int
permutation[]
(Input) - Array of length
n
containing the permutationpermutation[0]
, …,permutation[
n-1]
of the integers 0, …, n, where n =nRows
if the rows ofa
are to be permuted and n =nColumns
if the columns ofa
are to be permuted. - int
permute
(Input) - Keyword of type int. Argument
permute
must be eitherPERMUTE_ROWS
, if the rows ofa
are to be interchanged, orPERMUTE_COLUMNS
, if the columns ofa
are to be interchanged.
Return Value¶
Array of size nRows
× nColumns
containing the permuted input matrix
a
.
Description¶
Function permuteMatrix
interchanges the rows or columns of a matrix using
a permutation vector. The function permutes a column (row) at a time using
function permuteVector
. This process is continued until all the columns
(rows) are permuted. On completion, let B = result and \(p_i=
permutation \left[i\right]\), then \(B_{ij}=A_{pij}\) for all i, j.
Example¶
This example permutes the columns of a matrix a
.
from pyimsl.stat.permuteMatrix import permuteMatrix, PERMUTE_COLUMNS
from pyimsl.stat.writeMatrix import writeMatrix
a = [[3.0, 5.0, 1.0, 2.0, 4.0],
[3.0, 5.0, 1.0, 2.0, 4.0],
[3.0, 5.0, 1.0, 2.0, 4.0]]
permutation = [2, 3, 0, 4, 1]
output = permuteMatrix(a, permutation, PERMUTE_COLUMNS)
writeMatrix("permuted matrix", output,
rowNumberZero=True, colNumberZero=True)
Output¶
permuted matrix
0 1 2 3 4
0 1 2 3 4 5
1 1 2 3 4 5
2 1 2 3 4 5