I want to get or create numpy's amax functionality in Rust with the ndarray crate. So basically, I want to be able to get this behaviour in Rust:

>>> import numpy as np >>> arr = np.array(range(1, 28)).reshape((3, 3, 3)) >>> np.amax(arr, axis=1) array([[ 7, 8, 9], [16, 17, 18], [25, 26, 27]]) 

As far as I can see, there's no amax function in ndarray. How can I get the same functionality as mentioned in the above example with this ndarray array:

let arr = Array3::from_shape_vec((3, 3, 3), (1..28).collect()).unwrap(); 

1 Answer

You can do this using map_axis and min

let a_min = arr.map_axis(Axis(0), |view| *view.iter().min().unwrap() ) 

You can see a working example in the playground

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy