numjs
numjs copied to clipboard
Slicing odd and even indices
I have an array and want to extract the odd samples and the even samples. With numpy i would do:
even = a[::2]
odd = a[1::2]
Reading your docs it looks like what i need is:
even = a.slice([null,null,2]);
odd = a.slice([1, null, 2]);
Even works but odd spits out a single element...
In fact i have a 1d complex tensor disguised as a 2d tensor. And i want to extract the real and imaginary parts of both the even and odd samples. So i have so far
even= a.slice([null,null,2]);
evenreal = even.slice(null, 0);
evenimag = even.slice(null, 1);
odd = a.slice([1, null, 2]);
oddreal = odd.slice(null, 0);
oddimag = odd.slice(null,1);
so far only even and evenimag have the right dimensions. The rest haven't. I haven't checked the values yet
do a reshape first to go from [B,2] to [B//2,2,2] then slice appropriately with some flattening if required
@nicolaspanel I'm stuck on this again. Can you help?
Still having this issue. It seems the bug https://github.com/nicolaspanel/numjs/issues/19 still exists, it is not resolved in latest version (v0.16.1)