"Key" is very useful. Here's a simple illustration of how it works:
]egkeyvals=. 0 0 1 1 1 0,:1 2 3 4 5 6 NB. row 0 is keys, row 1 is values
0 0 1 1 1 0
1 2 3 4 5 6
(0{egkeyvals) +/ /. 1{egkeyvals NB. apply verb "+/" to values
according to keys
9 12
NB. 9=+/1 2 6 (values where key=0) and 12=+/3 4 5 (values where key=1)
Now, to blow your mind:
(+/ /.) / egkeyvals
9 12
On Wed, Nov 21, 2012 at 1:12 PM, Alex Giannakopoulos <
[email protected]> wrote:
> Well, I'm having a bit of trouble getting my head around "key", I'll keep
> at it though...
> However I was inspired by Raul's solution to come up with something that
> worked and I understood.
> Well, sort of understood anyway, why does the evenoddrows verb not need to
> be (0 2 |: @ reshape2s) ?
>
> reshape2s =. ;$~(2%~0{$),2,1{$
> evenoddrows =. 0 2 |: reshape2s
> evenoddrows i. 8 4
> 0 1 2 3
> 8 9 10 11
> 16 17 18 19
> 24 25 26 27
>
> 4 5 6 7
> 12 13 14 15
> 20 21 22 23
> 28 29 30 31
>
> Hope that's not too inefficient
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
Devon McCormick, CFA
^me^ at acm.
org is my
preferred e-mail
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm