bug-apl
[Top][All Lists]

## Re: [Bug-apl] EACH by axis

 From: Elias Mårtenson Subject: Re: [Bug-apl] EACH by axis Date: Mon, 31 Mar 2014 15:34:38 +0800

Jay, thanks for reminding me of the rank operator. I had forgotten about that one. :-)

Yes, in this case it would definitely do the right thing, but as you mention it won't allow you to work on other axes.

Regards,
Elias

On 31 March 2014 15:29, Jay Foad wrote:
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
>
>
>
> ⊃ {⍵[⍋⍵]}¨ ⊂[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.