From 7bf2aa4054b8378a76dff63acdccbcdad91f68e6 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Sat, 7 Aug 2021 20:41:31 -0400 Subject: BREAKING: Don't allow First of empty or reshaping empty to non-empty --- docs/doc/pick.html | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'docs/doc/pick.html') diff --git a/docs/doc/pick.html b/docs/doc/pick.html index b0e99195..a296d6c0 100644 --- a/docs/doc/pick.html +++ b/docs/doc/pick.html @@ -6,7 +6,7 @@

Pick

Pick () chooses elements from 𝕩 based on index lists from 𝕨. 𝕨 can be a plain list, or even one number if 𝕩 is a list, in order to get one element from 𝕩. It can also be an array of index lists, or have deeper array structure: each index list will be replaced with the element of 𝕩 at that index, effectively applying to 𝕨 at depth 1.

-

With no 𝕨, monadic 𝕩 takes the first element of 𝕩 in index order, or its fill element if 𝕩 is empty (causing an error if no fill is known).

+

With no 𝕨, monadic 𝕩 takes the first element of 𝕩 in index order, with an error if 𝕩 is empty.

While sometimes "scatter-point" indexing is necessary, using Pick to select multiple elements from 𝕩 is less array-oriented than Select (), and probably slower. Consider rearranging your data so that you can select along axes instead of picking out elements.

One element

When the left argument is a number, Pick gets an element from a list:

@@ -55,15 +55,12 @@ 4251 ⟨ 0 0 0 0 ⟩ -

If 𝕩 is empty then Pick always results in an error. First never gives an error: instead it returns the fill element for 𝕩.

-↗️
     ""
-' '
+

If 𝕩 is empty then First results in an error, like Pick.

+↗️
     ""
+ERROR
      π
-0
-     0↑<"  ",4
-⟨ "  " ⟨ 0 0 0 0 ⟩ ⟩
+ERROR
 
-

So one way to find the fill element for an array 𝕩 of any shape is 0𝕩.

In APL it's common to get the last element of a list with an idiom that translates to ⊑⌽, or First-Reverse. In BQN the most straightforward way is to select with index ¯1 instead. I also sometimes use Fold with the Right identity function.

↗️
    ⊑⌽ "last"
 't'
-- 
cgit v1.2.3