How to get a Slice/View rom an arbirary vec/iterable of integers(ie indixes)? #1183
-
Hello team, and thank you for this great library! I wonder if anyone came across/has done something like this before: I need to take a slice from an array based om an arbitrary, dynamic vec of integers(indexes). After thoroughly digging docs I did not find any way to do that. Firstly, Slice and slice info can be created from a single int or a range, but not from iterable or vec. Here is let ar = arr2(&[[1.,2.,3., 4.,5.,6.],[0., 0., 0., 0., 0., 0.,], [7., 8., 9., 10., 11., 12.]]); Say, I want to keep only indexes 0, 3 and 4 and rows 0 and 2. So essentially I want something like this: dbg!(ar.slice(s![&[0,2], &[0, 3, 4] )); and get: [[1.0, 4.0, 5.0],
[7.0, 10.0, 11.0]] Many thanks for any suggestions |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Views and thus slicing can only represent consistent strides. I.e you make a lattice that you overlay on top of the original array, skipping as many elements as the stride for that axis says. Thus we can't do this, since we don't have a regular grid here, we are skipping different numbers of steps in different places. However, .select(), the method, can copy out particular indexes along an axis. |
Beta Was this translation helpful? Give feedback.
Views and thus slicing can only represent consistent strides. I.e you make a lattice that you overlay on top of the original array, skipping as many elements as the stride for that axis says. Thus we can't do this, since we don't have a regular grid here, we are skipping different numbers of steps in different places.
However, .select(), the method, can copy out particular indexes along an axis.