Introduction to Array Manipulation

Arrays/Sets/Matrices are fundamental data structures in z^3. Manipulation of such data structures are often done using custom code in most languages. However, z^3 offers a ton of Array member functions that make it a breeze to handle and manipulate such data structures.

For example, take .chunks().

a=1..100;

This creates a list of 100 numbers. Now, let us make them into chunks of 10 each.

a.chunks(10)

gives

1 2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
31 32 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48 49 50
51 52 53 54 55 56 57 58 59 60
61 62 63 64 65 66 67 68 69 70
71 72 73 74 75 76 77 78 79 80
81 82 83 84 85 86 87 88 89 90
91 92 93 94 95 96 97 98 99 100


Simple, isn't it?

The result gives a 10x10 matrix filled with the sequence of numbers from 1 to 100.

Let us say we want to calculate the sum of each row in this 10x10 matrix. The $$ row wise mapping function comes to the rescue.

b=a.chunks(10) b.$$(SUM)

55
155
255
355
455
555
655
755
855
955