⍋ — Grade up / Grade up by
Function. Keys: Alt-Backslash 7. Hanzi: 升. Ranks: ∞ monadic, ∞ ∞ dyadic
⍋Y gives indices that sort major cells ascending. Stable; uses structural ordering, without tolerance.
⍋30 10 20 ⍝ [1 2 0]ₓ
v←30 10 20 ⋄ [⍋v]⌷v ⍝ 10 20 30
⍋2 1 2 1 ⍝ [1 3 0 2]ₓThe positions keep the name of Y’s first axis. Selecting with a grade along axis i sorts each column of a matrix with axes i and j:
x←["i":3 "j":4]⍴3 1 4 1 5 9 2 6 5 3 5 8
x.[(⍋⍠"i" x)] ⍝ ["i":3 "j":4]⍴[3 1 2 1⋄5 3 4 6⋄5 9 5 8]C⍋Y uses a character collation array C.
"cba"⍋"abc" ⍝ [2 1 0]ₓFast combinations
BPL computes each of these combinations by an algorithm of its own, in any spelling. Trains says which spellings BPL recognises.
| Combination | Applies to | Benefit |
|---|---|---|
k↑⍋Y, k↑⍋ Y or (k↑)∘⍋ |
a vector of reals or characters without keys | selects the first k positions of the grade, or the last -k, without ordering the rest |
↑⍋Y, i⌷⍋Y or i⊃⍋Y |
the same vectors | selects one position without ordering the rest |
⍋⍋Y, ⍋⍋ Y or ⍋∘⍋ |
any Y without keys on its first axis |
gives each major cell’s rank by inverting the first grade, without grading it again |
v←30 10 20 50 40 60 70 80 90 0
2↑⍋ v ⍝ [9 1]ₓ
⍋⍋ v ⍝ [3 1 2 5 4 6 7 8 9 0]ₓ
(•explain "2↑⍋ v").fast.rule ⍝ ["partial grade"]Inverse
⍋⁻P gives an array whose grade is the permutation P. Any other P is a DOMAIN error.
⍋⁻2 0 1 ⍝ [1 2 0]ₓ