argmax

Function argmax 

Source
pub fn argmax<T>(
    array: ArrayView<'_, T, Ix2>,
    axis: Option<usize>,
) -> Result<Array<usize, Ix1>, &'static str>
where T: Clone + PartialOrd,
Expand description

Return the indices of the maximum values along the specified axis

§Arguments

  • array - The input 2D array
  • axis - The axis along which to find the maximum values (0 for rows, 1 for columns, None for flattened array)

§Returns

A 1D array containing the indices of the maximum values

§Examples

use ndarray::array;
use scirs2_core::ndarray_ext::manipulation::argmax;

let a = array![[5, 2, 3], [4, 1, 6]];

// Find indices of maximum values along axis 0 (columns)
let result = argmax(a.view(), Some(0)).unwrap();
assert_eq!(result, array![0, 0, 1]); // The indices of max values in each column

// Find indices of maximum values along axis 1 (rows)
let result = argmax(a.view(), Some(1)).unwrap();
assert_eq!(result, array![0, 2]); // The indices of max values in each row

// Find index of maximum value in flattened array
let result = argmax(a.view(), None).unwrap();
assert_eq!(result[0], 5); // The index of the maximum value in the flattened array (row 1, col 2)