COLPERM

Purpose:

Randomly permutes the column order of an array.

Syntax:

COLPERM(s, idx)

(r, k) = COLPERM(s, idx)

s

-

A series or array, the input to randomize.

idx

-

Optional.  A series of column indices returned by a previous call to COLPERM. When supplied, the inverse permutation is applied to restore the array to its original column order. Omit to generate a new random permutation.

Returns:

A series or array with its rows randomly permuted.

 

(r, k) = COLPERM(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 COLPERM applies the inverse permutation and restores the original column order.

Example:

W1: transpose(1..5)

W2: colperm(w1)

 

W1 contains the 1x5 series {{1, 2, 3, 4, 5}}.

 

W2 contains the 1x5 series {{5, 4, 2, 1, 3}}. The actual result may differ.

Example:

W1: transpose(1..5)

W2: (r, k) = colperm(w1);r

W3: colperm(w2, k)

 

W1 contains the 1x5 series {{1, 2, 3, 4, 5}}.

 

W2 contains the 1x5 series {{5, 4, 2, 1, 3}}. The actual result may differ.

 

W3 contains the 1x5 series {{1, 2, 3, 4, 5}}, the original series.

Example:

W1: ravel(1..12, 4);tableview

W2: (r, k) = colperm(w1);r

W3: colperm(w2, k)

 

W1 == {{1, 5,  9},

       {2, 6, 10},

       {3, 7, 11},

       {4, 8, 12}}

 

W2 == {{5, 1,  9},

       {6, 2, 10},

       {7, 3, 11},

       {8, 4, 12}}

 

The actual result in W2 may differ.

 

W3 == {{1, 5,  9},

       {2, 6, 10},

       {3, 7, 11},

       {4, 8, 12}}

 

The columns off W1 are permuted in W2 and restored in W3.

Remarks:

COLPERM permutes the columns of an array using RANDPERM.

 

When idx is supplied, GRADE is applied to idx to obtain the inverse permutation and restores the columns to their original order.

 

The two-output form (r, k) = COLPERM(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 COLRANDOMIZE to independently shuffle the column elements within each row of an array.

 

See ROWPERM to permute the rows of an array.

 

See ROWRANDOMIZE  to independently shuffle the row elements within each column of an array.

 

See RANDOMIZE to arbitrarily reorder an array.

 

See RANDSAMPLE to return K random samples from a population.

See Also:

COLRANDOMIZE

GRADE

RANDOMIZE

RANDPERM

RANDSAMPLE

ROWPERM

ROWRANDOMIZE