This chapter covers rearranging the items of arrays: permuting, sorting, transposing, reversing, rotating and shifting.

This chapter covers rearranging the items of arrays: permuting, sorting, transposing, reversing, rotating and shifting.

16.1 Permutations

A permutation of a vector is another vector which has all the items of the first but not necessarily in the same order. For example, z is a permutation of y where:

y =: 'abcde' z =: 4 2 3 1 0 { y
abcde ecdba

The index vector 4 2 3 1 0 is itself a permutation of the indices 0 1 2 3 4, that is, i. 5, and hence is said to be a permutation vector of order 5.

Notice the effect of this permutation: the first and last items are interchanged and the middle three rotate position amongst themselves. Hence this permutation can be described as a combination of cycling two items and cycling three items. After 6 (= 2 * 3) applications of this permutation we return to the original vector.

   p =: 4 2 3 1 0 & {
y p y p p y p p p p p p y
abcde ecdba adbce abcde

The permutation 4 2 3 1 0 can be represented as a cycle of 2 and a cycle of 3. The verb to compute this cyclic representation is monadic C. .

Leave a comment

Your email address will not be published. Required fields are marked *


3 + = twelve

Leave a Reply