permuteMatrix¶
Permutes the rows or columns of a matrix.
Synopsis¶
permuteMatrix (a, permutation, permute)
Required Arguments¶
- float
a[[]](Input) - Matrix of size
nRows×nColumnsto be permuted. - int
permutation[](Input) - Array of length
ncontaining the permutationpermutation[0], …,permutation[n-1]of the integers 0, …, n, where n =nRowsif the rows ofaare to be permuted and n =nColumnsif the columns ofaare to be permuted. - int
permute(Input) - Keyword of type int. Argument
permutemust be eitherPERMUTE_ROWS, if the rows ofaare to be interchanged, orPERMUTE_COLUMNS, if the columns ofaare 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