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 approach:
(({~ |:@i.) >.@-:@#,2:) i.8
0 2 4 6
1 3 5 7
But that's probably a bit silly.
Thanks,
--
Raul
On Thu, Oct 9, 2014 at 6:00 PM, Andrey Paramonov <[email protected]> wrote:
> 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.
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm