M01ZAF inverts a permutation, and hence converts a rank vector to an index vector, or vice versa.
There are two common ways of describing a permutation using an integer vector
IPERM. 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
M01D
routines generate ranks, and the
M01E
routines 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 (see the example in
Section 9).
M01ZAF can be used to convert ranks to indices, or indices to ranks, as the two permutations are inverses of each another.
None.
If on entry
or
, explanatory error messages are output on the current error message unit (as defined by
X04AAF).
If
or
, elements
M1 to
M2 of
IPERM do not contain a permutation of the integers
M1 to
M2; on exit these elements are usually corrupted. To check the validity of a permutation without the risk of corrupting it, use
M01ZBF.
Not applicable.
None.
This example reads a matrix of real numbers and prints its rows
in ascending order as ranked by
M01DEF.
The program first calls
M01DEF
to rank the rows, and then calls M01ZAF to convert the rank vector to an index vector, which is used to refer to the rows in sorted order.