The function Select (β) reorganizes the array π© along one or more axes based on indices given by π¨. The result has the same depth as π©, since its elements are always elements of π©. This means it differs from Pick (β), which takes elements from π© but can arrange them in any nested structure, including returning an element directly.
The monadic form First Cell (β) gets the major cell with index 0, so that βπ© is identical to 0βπ©.
Each axis of a BQN array is numbered starting at zero. Major cells are arranged along the first axis; in accordance with the leading axis principle, Select returns a major cell of π© when π¨ is an atom.
2 β "abcdef" # An enclosed element βΒ· Β·'c' β 2 β "abcdef" # Pick gets a non-enclosed element 'c' 2 β >"nul"βΏ"one"βΏ"two"βΏ"tre"βΏ"for" "two" 0 β <5 # No first axis to select from ERROR
As a major cell of π©, the result has rank one less than it and its shape is 1ββ’π©. π© must have rank one or more.
The index π¨ has to be an integer less than β π©. It can be negative, in which case it must be greater than or equal to -β π©. Negative indices select from the end of π©, in that Β―1 indicates the last major cell and -β π© indicates the first. If β π© is 0, then no index is valid.
Β―2 β "abcdef" βΒ· Β·'e' β 0 β "" ERROR
The monadic case First Cell (βπ©) is identical to 0βπ©. It has the same restrictions: π© must have rank 1 or more, and length 1 or more (this differs from First (β), which removes the length requirement to return a fill element).
β "abc" βΒ· Β·'a' β β "abc"β"def" "abc" β β "abc" "abc" β 'a' ERROR
If π¨ is an array of numbers (including any empty array), then each number indicates a major cell of π©. In the simplest case, a list of numbers gives a result with the same rank as π© but maybe not the same length.
2βΏ3βΏ3βΏ0βΏ4βΏ1 β "OlZEt" "ZEEOtl" β¨β© β "OlZEt" β¨β©
To find the first and last cells of π©, use 0βΏΒ―1 for the left argument.
β’ m β 3βΏ5βΏ7βΏ11 |β ΓΛβ7 ββ β΅ 0 1 1 0 1 1 0 0 1 4 4 1 0 1 0 1 4 2 2 4 1 0 1 4 9 5 3 3 β 0βΏΒ―1 β m ββ β΅ 0 1 1 0 1 1 0 0 1 4 9 5 3 3 β
More generally, π¨ can be an array of any rank. Each of its 0-cellsβcontaining a single numberβis replaced with a cell of π© in the result. The result's shape is then made up of the shape of π¨ and the major cell shape of π©: it's (β’π¨)βΎ1ββ’π©. When π© is a list, the result has the same shape as π¨. Elements of π¨ are replaced one-for-one with elements of π©.
2|m ββ β΅ 0 1 1 0 1 1 0 0 1 0 0 1 0 1 0 1 0 0 0 0 1 0 1 0 1 1 1 1 β (2|m) β " *" ββ β΅" ** ** * * * * * * ****" β
Another special case is when π¨ is a unit. Now the result shape will be the major cell shape of π©. In fact it's the same as the atom case above, that is, for a number n, (<n)βπ© is the same as nβπ©.
The general case can result in a complicated array. Remember that the initial axes come from π¨ while later ones come from π©.
"awA0" +β β4 ββ β΅"abcd wxyz ABCD 0123" β 2 β β4 ββ β΅ 0 1 1 2 2 3 β (2 β β4) β "awA0" +β β4 ββ β"abcd wxyz Β·wxyz ABCD Β·ABCD 0123" β