Randomly permutes the row order of an array.
ROWPERM(s, idx)
(r, k) = ROWPERM(s, idx)
s |
- |
A series or array, the input to randomize. |
idx |
- |
Optional. A series of row indices returned by a previous call to ROWPERM. When supplied, the inverse permutation is applied to restore the array to its original row order. Omit to generate a new random permutation. |
A series or array with its rows randomly permuted.
(r, k) = ROWPERM(s) returns both the permuted array r and the index series k that describes the reordering. Passing k as the idx argument in a subsequent call to ROWPERM applies the inverse permutation and restores the original row order.
W1: 1..5;tableview
W2: rowperm(w1)
W1 contains the 5x1 series {1, 2, 3, 4, 5}.
W2 contains the 5x1 series {5, 4, 2, 1, 3}. The actual result may differ.
W1: 1..5;tableview
W2: (r, k) = rowperm(w1);r
W3: rowperm(w2, k)
W1 contains the 5x1 series {1, 2, 3, 4, 5}.
W2 contains the 5x1 series {5, 4, 2, 1, 3}. The actual result may differ.
W3 contains the 5x1 series {1, 2, 3, 4, 5}, the original series.
W1: ravel(1..12, 4);tableview
W2: (r, k) = rowperm(w1);r
W3: rowperm(w2, k)
W1 == {{1, 5, 9},
{2, 6, 10},
{3, 7, 11},
{4, 8, 12}}
W2 == {{3, 7, 11},
{2, 6, 10},
{1, 5, 9},
{4, 8, 12}}
The actual result in W2 may differ.
W3 == {{1, 5, 9},
{2, 6, 10},
{3, 7, 11},
{4, 8, 12}}
The rows of each column of W1 are permuted in W2 and restored in W3.
ROWPERM permutes the rows of an array using RANDPERM.
When idx is supplied, GRADE is applied to idx to obtain the inverse permutation and restores the rows to their original order.
The two-output form (r, k) = ROWPERM(s) captures the index series k. Passing k back as idx in a second call is the standard way to round-trip the data.
See ROWRANDOMIZE to independently shuffle the row elements within each column of an array.
See COLPERM to permute the columns of an array.
See COLRANDOMIZE to independently shuffle the column elements within each row of an array.
See RANDOMIZE to arbitrarily reorder an array.
See RANDSAMPLE to return K random samples from a population.