diff options
Diffstat (limited to 'docs/doc/select.html')
| -rw-r--r-- | docs/doc/select.html | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/docs/doc/select.html b/docs/doc/select.html index aaa36cc3..566f6484 100644 --- a/docs/doc/select.html +++ b/docs/doc/select.html @@ -51,7 +51,7 @@ <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"><a class="header" href="#single-selection">Single selection</a></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> +<p>The <a href="array.html#cells">major cells</a> of an array are arranged along the <a href="leading.html">first axis</a> and numbered starting at 0. For a natural number <code><span class='Value'>๐จ</span></code>, Select returns the major cell of <code><span class='Value'>๐ฉ</span></code> with index <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=MiDiio8gImFiY2RlZiIgICMgQW4gZW5jbG9zZWQgZWxlbWVudAoKMiDiipEgImFiY2RlZiIgICMgUGljayBnZXRzIGEgbm9uLWVuY2xvc2VkIGVsZW1lbnQKCjIg4oqPID4ibnVsIuKAvyJvbmUi4oC/InR3byLigL8idHJlIuKAvyJmb3IiCgowIOKKjyA8NSAgIyBObyBmaXJzdCBheGlzIHRvIHNlbGVjdCBmcm9t">โ๏ธ</a><pre> <span class='Number'>2</span> <span class='Function'>โ</span> <span class='String'>"abcdef"</span> <span class='Comment'># An enclosed element </span>โยท ยท'c' @@ -66,7 +66,7 @@ <span class='Number'>0</span> <span class='Function'>โ</span> <span class='Function'><</span><span class='Number'>5</span> <span class='Comment'># No first axis to select from </span><span class='Error'>Error: โ: ๐ฉ cannot be a unit</span> </pre> -<p>As a major cell of <code><span class='Value'>๐ฉ</span></code>, the result has rank one less than it and its shape is <code><span class='Number'>1</span><span class='Function'>โโข</span><span class='Value'>๐ฉ</span></code>. <code><span class='Value'>๐ฉ</span></code> must have rank one or more.</p> +<p>As a major cell, the result has rank one less than <code><span class='Value'>๐ฉ</span></code> and shape <code><span class='Number'>1</span><span class='Function'>โโข</span><span class='Value'>๐ฉ</span></code>. Of course <code><span class='Value'>๐ฉ</span></code> must have at least one axis to select along, or there are no major cells and you'll get an error.</p> <p>The index <code><span class='Value'>๐จ</span></code> has to be an integer less than <code><span class='Function'>โ </span><span class='Value'>๐ฉ</span></code>. It can be negative, in which case it must be greater than or equal to <code><span class='Function'>-โ </span><span class='Value'>๐ฉ</span></code>. Negative indices select from the end of <code><span class='Value'>๐ฉ</span></code>, in that <code><span class='Number'>ยฏ1</span></code> indicates the last major cell and <code><span class='Function'>-โ </span><span class='Value'>๐ฉ</span></code> indicates the first. If <code><span class='Function'>โ </span><span class='Value'>๐ฉ</span></code> is 0, then no index is valid.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=wq8yIOKKjyAiYWJjZGVmIgoKMCDiio8gIiI=">โ๏ธ</a><pre> <span class='Number'>ยฏ2</span> <span class='Function'>โ</span> <span class='String'>"abcdef"</span> โยท @@ -76,6 +76,7 @@ <span class='Number'>0</span> <span class='Function'>โ</span> <span class='String'>""</span> <span class='Error'>Error: โ: Indexing out-of-bounds (๐จโก0, 0โกโ ๐ฉ)</span> </pre> +<h3 id="first-cell"><a class="header" href="#first-cell">First Cell</a></h3> <p>The monadic case First Cell (<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>. It has the same restrictions: <code><span class='Value'>๐ฉ</span></code> must have rank 1 or more, and length 1 or more.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4oqPICJhYmMiCgriio8gImFiYyLiiY0iZGVmIgoK4oqPIOKJjSAiYWJjIgoK4oqPICdhJw==">โ๏ธ</a><pre> <span class='Function'>โ</span> <span class='String'>"abc"</span> โยท @@ -92,7 +93,7 @@ <span class='Error'>Error: โ: Argument cannot be an atom</span> </pre> <h2 id="first-axis-selection"><a class="header" href="#first-axis-selection">First-axis selection</a></h2> -<p>If <code><span class='Value'>๐จ</span></code> is an array of numbers (including any empty array), then each number indicates a major cell of <code><span class='Value'>๐ฉ</span></code>. In the simplest case, a list of numbers gives a result with the same rank as <code><span class='Value'>๐ฉ</span></code> but maybe not the same length.</p> +<p>If <code><span class='Value'>๐จ</span></code> is an array of numbers (including any empty array), then each number indicates a major cell of <code><span class='Value'>๐ฉ</span></code>. In the simplest case, a list of numbers gives a result with the same rank as <code><span class='Value'>๐ฉ</span></code> but the length 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=MuKAvzPigL8z4oC/MOKAvzTigL8xIOKKjyAiT2xaRXQiCgrin6jin6kg4oqPICJPbFpFdCI=">โ๏ธ</a><pre> <span class='Number'>2</span><span class='Ligature'>โฟ</span><span class='Number'>3</span><span class='Ligature'>โฟ</span><span class='Number'>3</span><span class='Ligature'>โฟ</span><span class='Number'>0</span><span class='Ligature'>โฟ</span><span class='Number'>4</span><span class='Ligature'>โฟ</span><span class='Number'>1</span> <span class='Function'>โ</span> <span class='String'>"OlZEt"</span> "ZEEOtl" @@ -183,4 +184,4 @@ โจ 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>. 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> +<p>Selection only ever applies to leading axes of <code><span class='Value'>๐ฉ</span></code>. However, you can skip some leading axes using <a href="rank.html">Rank</a> modifiers <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> |
