Arrays — Scalars, Vectors, Matrices¶
In APL, everything is an array. There are no separate types for single numbers, lists, and tables — they're all arrays of different rank (number of dimensions).
Scalars¶
A scalar is a single value — a number or a character. It has rank 0.
Vectors¶
A vector is a one-dimensional sequence of values. Type numbers separated by spaces:
A character vector (string) is written with single quotes:
You can find the number of elements in a vector with ⍴ (rho — shape):
Matrices¶
A matrix is a two-dimensional array with rows and columns. You create one by reshaping a vector:
The left argument to ⍴ is the desired shape (2 rows, 3 columns). The right argument provides the data.
The shape of a matrix is a 2-element vector: rows and columns.
Higher-rank arrays¶
Arrays can have three or more dimensions. A rank-3 array has planes, rows, and columns:
Note
MARPLE displays planes separated by a blank line.
Rank: the number of dimensions¶
The rank of an array is how many dimensions it has:
| Array | Rank | Shape example |
|---|---|---|
| Scalar | 0 | (empty) |
| Vector | 1 | 5 |
| Matrix | 2 | 3 4 |
| Cube | 3 | 2 3 4 |
You can find the rank of an array with ⍴⍴ (shape of the shape):
Flat arrays¶
MARPLE uses flat arrays: every element is a simple scalar (a number or a character). There are no arrays inside arrays (no nesting). This is different from Dyalog APL and APL2, which allow nested arrays.
If you're coming from another APL, see How MARPLE Differs for details on what this means in practice.
Key points¶
- Everything in APL is an array
- Arrays have a shape (found with
⍴) and a rank (number of dimensions) - Vectors are rank 1, matrices are rank 2, and so on
- MARPLE arrays are flat — elements are always simple scalars
- Data is stored in row-major order (last axis varies fastest)