Reshape and Iota — Building Arrays¶
Two functions you'll use constantly: ⍳ (iota) to generate sequences and ⍴ (rho) to shape them.
Iota: generating sequences¶
Monadic ⍳ generates integers from 1 to its argument:
Note
MARPLE's default index origin is 1 (⎕IO←1), so ⍳5 starts at 1. Some APLs default to 0.
Iota is often the starting point for building data:
Reshape: ⍴¶
Dyadic ⍴ reshapes data into a given shape:
If you provide fewer elements than needed, they recycle:
This is useful for creating arrays filled with a constant, identity-like patterns, or repeating sequences.
Shape: asking about dimensions¶
Monadic ⍴ returns the shape of an array:
The number of elements in the shape tells you the rank:
Ravel: ,¶
Monadic , (ravel) flattens any array into a vector:
Catenate: ,¶
Dyadic , joins arrays along the last axis:
Putting it together¶
These building blocks combine naturally:
⍝ A multiplication table
(⍳5) ∘.× (⍳5)
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25
⍝ Count of elements
×/ ⍴ 3 4 5 ⍴ 0
60
Key points¶
⍳Ngenerates the integers 1 through Nshape ⍴ datareshapes data into the given dimensions (recycling if needed)⍴ arrayreturns the shape;⍴⍴ arrayreturns the rank,ravels (monadic) or catenates (dyadic)- These functions are the basic toolkit for creating and exploring arrays