Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Rust ndarray: How can i select rows of an array from indexes

I have a two dimensional array Array2, i’d like to be able of selecting rows

use ndarray::{Array2, Axis};

let subarray: Array2 = my_array.select(Axis(0), &[0,2,5]);

With that simple code i can select first, third and sixth row, but what about when the target indexes are built at run time, i mean i’d like to select from a Vector or any iterable that could be the input of a function, for example.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can get the slice by simply borrowing on a Vector

let index = vec![0, 2, 4];
let subarray = my_array.select(Axis(0), &index);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading