diff options
Diffstat (limited to 'docs/doc/select.html')
| -rw-r--r-- | docs/doc/select.html | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/docs/doc/select.html b/docs/doc/select.html index 48f2af19..61a0f38d 100644 --- a/docs/doc/select.html +++ b/docs/doc/select.html @@ -48,7 +48,7 @@ </g> </svg> -<p>The function Select (<code><span class='Function'>β</span></code>) reorganizes the array <code><span class='Value'>π©</span></code> along one or more axes based on <a href="indices.html">indices</a> given by <code><span class='Value'>π¨</span></code>. The result has the same <a href="depth.html">depth</a> as <code><span class='Value'>π©</span></code>, since its elements are always elements of <code><span class='Value'>π©</span></code>. This means it differs from Pick (<code><span class='Function'>β</span></code>), which takes elements from <code><span class='Value'>π©</span></code> but can arrange them in any nested structure, including returning an element directly.</p> +<p>The function Select (<code><span class='Function'>β</span></code>) reorganizes the array <code><span class='Value'>π©</span></code> along one or more axes based on <a href="indices.html">indices</a> given by <code><span class='Value'>π¨</span></code>. The result has the same <a href="depth.html">depth</a> as <code><span class='Value'>π©</span></code>, since its elements are always elements of <code><span class='Value'>π©</span></code>. This means it differs from <a href="pick.html">Pick</a> (<code><span class='Function'>β</span></code>), which takes elements from <code><span class='Value'>π©</span></code> but can arrange them in any nested structure, including returning an element directly.</p> <p>The monadic form First Cell (<code><span class='Function'>β</span></code>) gets the major cell with index 0, so that <code><span class='Function'>β</span><span class='Value'>π©</span></code> is identical to <code><span class='Number'>0</span><span class='Function'>β</span><span class='Value'>π©</span></code>.</p> <h2 id="single-selection">Single selection</h2> <p>Each axis of a BQN array is numbered starting at zero. Major cells are arranged along the first axis; in accordance with the <a href="leading.html">leading axis</a> principle, Select returns a major cell of <code><span class='Value'>π©</span></code> when <code><span class='Value'>π¨</span></code> is an atom.</p> @@ -114,7 +114,8 @@ ERROR 0 1 4 9 5 3 3 β </pre> -<p>More generally, <code><span class='Value'>π¨</span></code> can be an array of any rank. Each of its 0-cellsβcontaining a single numberβis replaced with a cell of <code><span class='Value'>π©</span></code> in the result. The result's shape is then made up of the shape of <code><span class='Value'>π¨</span></code> and the major cell shape of <code><span class='Value'>π©</span></code>: it's <code><span class='Paren'>(</span><span class='Function'>β’</span><span class='Value'>π¨</span><span class='Paren'>)</span><span class='Function'>βΎ</span><span class='Number'>1</span><span class='Function'>ββ’</span><span class='Value'>π©</span></code>. When <code><span class='Value'>π©</span></code> is a list, the result has the same shape as <code><span class='Value'>π¨</span></code>. Elements of <code><span class='Value'>π¨</span></code> are replaced one-for-one with elements of <code><span class='Value'>π©</span></code>.</p> +<p>More generally, <code><span class='Value'>π¨</span></code> can be an array of any rank. Each of its 0-cellsβcontaining a single numberβis replaced with a cell of <code><span class='Value'>π©</span></code> in the result. The result's shape is then made up of the shape of <code><span class='Value'>π¨</span></code> and the major cell shape of <code><span class='Value'>π©</span></code>: it's <code><span class='Paren'>(</span><span class='Function'>β’</span><span class='Value'>π¨</span><span class='Paren'>)</span><span class='Function'>βΎ</span><span class='Number'>1</span><span class='Function'>ββ’</span><span class='Value'>π©</span></code>.</p> +<p>When <code><span class='Value'>π©</span></code> is a list, the result has the same shape as <code><span class='Value'>π¨</span></code>. Elements of <code><span class='Value'>π¨</span></code> are replaced one-for-one with elements of <code><span class='Value'>π©</span></code>.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=MnxtCgooMnxtKSDiio8gIiAqIg==">βοΈ</a><pre> <span class='Number'>2</span><span class='Function'>|</span><span class='Value'>m</span> ββ β΅ 0 1 1 0 1 1 0 @@ -168,8 +169,8 @@ ERROR β¨ 1 3 β© β¨ 1 0 β© β¨ 1 0 β© β </pre> -<p>Using a <a href="range.html">range</a> for <code><span class='Value'>π©</span></code> shows the structure of the selected elements more clearly, because each element is its own index. Each element of <code><span class='Value'>π¨</span></code> acts independently, giving a structure like the Table modifier.</p> -<p>While <code><span class='Value'>π¨</span></code> must have rank one or less, its elements can have any rank. When the elements are units, the corresponding axis of <code><span class='Value'>π©</span></code> disappears from the result. We can select a 0-cell of <code><span class='Value'>π©</span></code> in this way, although the more common case or selecting an element is handled by Pick.</p> +<p>Using a <a href="range.html">range</a> for <code><span class='Value'>π©</span></code> shows the structure of the selected elements more clearly, because each element is its own index. Each element of <code><span class='Value'>π¨</span></code> acts independently, giving a structure like the <a href="map.html#table">Table</a> modifier.</p> +<p>While <code><span class='Value'>π¨</span></code> must have rank one or less, its elements can have any rank. When the elements are units, the corresponding axis of <code><span class='Value'>π©</span></code> disappears from the result. We can select a 0-cell of <code><span class='Value'>π©</span></code> in this way, although the more common case of selecting an element is handled by <a href="pick.html">Pick</a>.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4p+oPDQsPDUsPDHin6kg4oqPICgz4qWKMTAp4qWK4oaVMWUzCuKfqCA0LCA1LCAx4p+pIOKKkSAoM+KlijEwKeKliuKGlTFlMw==">βοΈ</a><pre> <span class='Bracket'>β¨</span><span class='Function'><</span><span class='Number'>4</span><span class='Separator'>,</span><span class='Function'><</span><span class='Number'>5</span><span class='Separator'>,</span><span class='Function'><</span><span class='Number'>1</span><span class='Bracket'>β©</span> <span class='Function'>β</span> <span class='Paren'>(</span><span class='Number'>3</span><span class='Function'>β₯</span><span class='Number'>10</span><span class='Paren'>)</span><span class='Function'>β₯β</span><span class='Number'>1e3</span> βΒ· Β· 451 @@ -182,4 +183,4 @@ ERROR β¨ 450 451 452 453 454 455 456 457 458 459 β© </pre> <p>If an element of <code><span class='Value'>π¨</span></code> has rank more than 1, it increases the rank of <code><span class='Value'>π©</span></code> rather than decreasing it. The general rule is that in the result, one axis of <code><span class='Value'>π©</span></code> is replaced by all the axes of the corresponding element of <code><span class='Value'>π¨</span></code> (trailing axes are unchanged). So the final shape <code><span class='Function'>β’</span><span class='Value'>π¨</span><span class='Function'>β</span><span class='Value'>π©</span></code> is <code><span class='Paren'>(</span><span class='Function'>βΎβ’</span><span class='Modifier'>Β¨</span><span class='Value'>π¨</span><span class='Paren'>)</span><span class='Function'>βΎ</span><span class='Value'>π¨</span><span class='Function'>β </span><span class='Modifier2'>βΈ</span><span class='Function'>ββ’</span><span class='Value'>π©</span></code>. But this shape doesn't affect the elements retrieved from <code><span class='Value'>π©</span></code>. In all cases, using <code><span class='Function'>β₯</span><span class='Modifier'>Β¨</span><span class='Value'>π¨</span></code> for the left argument and then <a href="reshape.html">reshaping</a> the result would yield the same value.</p> -<p>Selection only ever applies to leading axes of <code><span class='Value'>π©</span></code>. But you can skip some leading axes using <code><span class='Modifier'>Λ</span></code> or <code><span class='Modifier2'>β</span></code>, to select on any contiguous set of axes. In particular, use the one-axis case <code><span class='Value'>π¨</span><span class='Modifier2'>βΈ</span><span class='Function'>β</span><span class='Modifier2'>β</span><span class='Paren'>(</span><span class='Function'>-</span><span class='Value'>k</span><span class='Paren'>)</span> <span class='Value'>π©</span></code> to select along axis <code><span class='Value'>k</span></code> of <code><span class='Value'>π©</span></code>.</p> +<p>Selection only ever applies to leading axes of <code><span class='Value'>π©</span></code>. However, you can skip some leading axes using <code><span class='Modifier'>Λ</span></code> or <code><span class='Modifier2'>β</span></code>, to select on any contiguous set of axes. In particular, use the one-axis case <code><span class='Value'>π¨</span><span class='Modifier2'>βΈ</span><span class='Function'>β</span><span class='Modifier2'>β</span><span class='Paren'>(</span><span class='Function'>-</span><span class='Value'>k</span><span class='Paren'>)</span> <span class='Value'>π©</span></code> to select along axis <code><span class='Value'>k</span></code> of <code><span class='Value'>π©</span></code>.</p> |
