numjs icon indicating copy to clipboard operation
numjs copied to clipboard

Slicing odd and even indices

Open pfeatherstone opened this issue 5 years ago • 4 comments

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...

pfeatherstone avatar May 06 '20 14:05 pfeatherstone

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

pfeatherstone avatar May 06 '20 14:05 pfeatherstone

do a reshape first to go from [B,2] to [B//2,2,2] then slice appropriately with some flattening if required

pfeatherstone avatar Jan 27 '21 11:01 pfeatherstone

@nicolaspanel I'm stuck on this again. Can you help?

pfeatherstone avatar Dec 15 '22 09:12 pfeatherstone

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)

1isten avatar Mar 11 '24 08:03 1isten