diff options
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/group.md | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/doc/group.md b/doc/group.md index 1d9eb3f4..6451d678 100644 --- a/doc/group.md +++ b/doc/group.md @@ -10,7 +10,7 @@ Once defined, the old BQN Key (dyadic) is `⍷⊸⊐⊸⊔` and Group (monadic) ## Definition -Group operates on a list of indices and a list of values to produce a list of groups of values (which are lists). The lists of indices and values have the same length, and each value is paired with the index at the same position. That index indicates the result group the value should go into, with an "index" of ¯1 indicating that the value should be dropped and not appear in the result. +Group operates on a numeric list of indices and a value array, treated as a list of its major cells, to produce a list of groups, each of which is a selection from the values. The indices and values have the same length, and each value cell is paired with the index at the same position. That index indicates the result group the value should go into, with an "index" of ¯1 indicating that it should be dropped and not appear in the result. 0‿1‿2‿0‿1 ≍ "abcde" ⍝ Corresponding indices and values ┌ @@ -64,9 +64,31 @@ When Group is called dyadically, the left argument is used for the indices and t Here, the index 2 appears at indices 0 and 3 while the index 3 appears at index 1. +### Multidimensional grouping + +Dyadic Group allows the right argument to be grouped along multiple axes by using a nested left argument. In this case, the left argument must be a vector of numeric vectors, and the result has rank `≠𝕨` while its elements—as always—have the same rank as `𝕩`. The result shape is `1+⌈´¨𝕨`, while the shape of element `i⊑𝕨⊔𝕩` is `i+´∘=¨𝕨`. If every element of `𝕨` is sorted ascending and contains only non-negative numbers, we have `𝕩≡∾𝕨⊔𝕩`, that is, Join is the inverse of Partition. + +Here we split up a rank-2 array into a rank-2 array of rank-2 arrays. Along the first axis we simply separate the first pair and second pair of rows—a partition. Along the second axis we separate odd from even indices. + + ⟨0‿0‿1‿1,0‿1‿0‿1‿0‿1‿0⟩⊔(10×↕4)+⌜↕7 + ┌ + ┌ ┌ + 0 2 4 6 1 3 5 + 10 12 14 16 11 13 15 + ┘ ┘ + ┌ ┌ + 20 22 24 26 21 23 25 + 30 32 34 36 31 33 35 + ┘ ┘ + ┘ + +Each group `i⊑𝕨⊔𝕩` is composed of the cells `j<¨⊸⊏𝕩` such that `i≢j⊑¨𝕨`. The groups retain their array structure and ordering along each argument axis. Using multidimensional Replicate we can say that `i⊑𝕨⊔𝕩` is `(i=𝕨)/𝕩`. + +The monadic case works similarly: Group Indices always satisfies `⊔𝕩 ←→ 𝕩⊔↕≠⚇1 x`. As with `↕`, the depth of the result of Group Indices is always one greater than that of its argument. A depth-0 argument is not allowed. + ## Properties -Group is closely related to the inverse of Indices, `/⁼`. In fact, inverse Indices gives the number of elements in each group for monadic Group: +Group is closely related to the inverse of Indices, `/⁼`. In fact, inverse Indices called on the index argument gives the length of each group: ≠¨⊔ 2‿3‿1‿2 [ 0 1 2 1 ] |
