[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Bug-apl] EACH by axis
From: |
Jay Foad |
Subject: |
Re: [Bug-apl] EACH by axis |
Date: |
Mon, 31 Mar 2014 08:29:12 +0100 |
On 31 March 2014 04:51, Elias Mårtenson <address@hidden> wrote:
> I keep wanting to be able to apply an axis argument to the ¨ (EACH)
> operator. I.e, to sort an array rows, I wanted to do:
>
> {⍵[⍋⍵]}¨[2] foo
>
>
> Instead, I had to do:
>
> ⊃ {⍵[⍋⍵]}¨ ⊂[2] foo
>
>
> Would it make sense to be able to specify an axis number to the the EACH
> operator as an extension?
Hi Elias,
Have you considered using the Rank operator?
{⍵[⍋⍵]}⍤1(4 3⍴'FEEFIEFOEFUM')
EEF
EFI
EFO
FMU
There is a bit of tension in APL between these two different ways of
solving the same kinds of problem: primitives-with-axis, and the Rank
operator.
- Primitives-with-axis are a bit ad hoc. Every primitive interprets
the axis specification in a different way, and some primitives (like
Each) don't support it at all.
- By contrast, the Rank operator is completely uniform and applies to
all functions.
- But the Rank operator restricts you to dividing the argument up
along the leading axes. (Some would argue that this restriction is a
good thing.) E.g. you can use it to sort each row of a matrix, but not
to sort each column.
Jay.