Documentation
Mathematica
Built-in Functions
Advanced Documentation
Linear Algebra
Sparse Arrays

Matrix Permutations
Many matrix techniques rely on ordering a matrix in particular ways. For example, some techniques try to order the matrix to put elements on the diagonal, while others try to group certain elements into dense blocks. The Mathematica function Part is very well suited to applying permutations to the rows and columns of a matrix.

Applying permutations to matrices.
This generates a random matrix.
In[1]:=
Out[2]//MatrixForm=
Now the matrix will be reordered so that the rows with smallest 2-norm are first. (Norms are discussed in a later section.) First, the norm of each row is computed.
In[3]:=
Out[3]=
This computes the permutation that is necessary to reorder the matrix.
In[4]:=
Out[4]=
This applies the ordering to the rows of the matrix; the result has rows with smallest 2-norms first.
In[5]:=
Out[6]//MatrixForm=
Now the inverse permutation is applied using part assignment. Note that this modifies the matrix held by the symbol pmat. Part assignment is described previously.
In[7]:=
Out[8]//MatrixForm=