Behalf Of robert
therriault
Sent: Thursday, October 09, 2014 6:15 PM
To: programm...@jsoftware.com
Subject: Re: [Jprogramming] Splitting vector
Hi Andrey,
My first idea is infix, the dyadic mode of \ feeding into monadic transpose
|:
t=. |: @: (_2 ]\ ])
t 0 1 2 3 4 5 6 7
0 2 4 6
1 3 5 7
Others
And there is "key"
(]/.~2|i.@#)i.8
0 2 4 6
1 3 5 7
which handles the odd case with an easy variant
(
I'd probably go with
i. 8
0 1 2 3 4 5 6 7
|:_2]\ i.8
0 2 4 6
1 3 5 7
But I see that Bob Therriault has already proposed this mechanism.
You could also do something using selection masks,
I'd probably go with
i. 8
0 1 2 3 4 5 6 7
|:_2]\ i.8
0 2 4 6
1 3 5 7
But I see that Bob Therriault has already proposed this mechanism.
You could also do something using selection masks, but I see that Pascal
Jasmin has already proposed something along that line.
So here's another approac
Hi Andrey,
My first idea is infix, the dyadic mode of \ feeding into monadic transpose |:
t=. |: @: (_2 ]\ ])
t 0 1 2 3 4 5 6 7
0 2 4 6
1 3 5 7
Others will have more informed feelings about the best way, but this would work.
Cheers, bob
On Oct 9, 2014, at 3:00 PM, Andrey Paramonov wrot
ot;
Cc:
Sent: Thursday, October 9, 2014 6:00 PM
Subject: [Jprogramming] Splitting vector
Hello everyone,
What is the best way in J to split a vector into two vectors by even and odd
indices? For example, for this input
0 1 2 3 4 5 6 7
I want the following output
0 2 4
Hello everyone,
What is the best way in J to split a vector into two vectors by even and odd
indices? For example, for this input
0 1 2 3 4 5 6 7
I want the following output
0 2 4 6
1 3 5 7
Thank you.