Indexing with From¶
From (⌷) is MARPLE's functional indexing primitive. It selects major cells — subarrays along the first axis — and it composes with the rank operator for arbitrary-axis selection.
Why From?¶
Bracket indexing (M[i;j]) works, but it's special syntax — it can't be passed to operators, can't be used in dfns as a first-class value, and the number of semicolons is tied to the array's rank. From is a proper function that composes with everything.
Basic usage: selecting major cells¶
For a vector, major cells are individual elements. For a matrix, major cells are rows:
For a rank-3 array, major cells are matrices:
Result shape¶
The result shape is always (⍴i) , 1↓⍴Y — the shape of the index, followed by the shape of a single major cell.
⍴ 1 3 ⌷ M ⍝ 2 rows, each of 5 columns
2 5
⍴ (2 3⍴1 2 1 2 1 2) ⌷ V ⍝ 2×3 matrix of selections from V
2 3
From + Rank: selecting along other axes¶
Since From selects along the first axis, and rank controls which cells the function sees, combining them reaches any axis.
Column selection¶
Apply From at rank 1 to select within each row:
Left rank 0 (each index is a scalar), right rank 1 (each row is a 1-cell). The scalar 3 is paired with each row, selecting the 3rd element.
For multiple columns:
Rectangular cross-sections¶
Select rows first, then columns:
Compare with bracket indexing: M[1 3; 2 4] — same result, but From composes with operators.
Equivalence with bracket indexing¶
| Bracket syntax | From + Rank | Meaning |
|---|---|---|
V[i] |
i ⌷ V |
Select from vector |
M[i;] |
i ⌷ M |
Select rows |
M[;j] |
j (⌷⍤1) M |
Select columns |
M[i;j] |
j (⌷⍤1) i ⌷ M |
Rows then columns |
When to use which¶
Use From when you want composability — passing indexing to operators, writing rank-independent code, or building reusable tools.
Use bracket indexing when you want a quick, readable cross-section and don't need to compose.
Both are available. Use whichever is clearer for the task at hand.
Key points¶
i ⌷ Yselects major cells ofYat indicesi- Result shape:
(⍴i) , 1↓⍴Y - Combine with rank to select along any axis:
j (⌷⍤1) Mfor columns - From is a proper function — it composes with operators and works in dfns
- Bracket indexing is retained for convenience