Skip to main content

argsort

Function argsort 

Source
pub fn argsort<T>(
    array: &Array<T>,
    axis: Option<isize>,
    _kind: Option<&str>,
    _order: Option<&[&str]>,
) -> Result<Array<usize>>
where T: PartialOrd + Clone + Zero,
Expand description

Returns the indices that would sort an array

§Parameters

  • array - Input array to sort
  • axis - Axis along which to sort. If None, the array is flattened before sorting
  • kind - Sorting algorithm (currently only supports default stable sort)
  • order - Not used (for NumPy compatibility)

§Returns

Array of indices that sort the array along the specified axis

§Examples

use numrs2::prelude::*;

let a = Array::from_vec(vec![3.0, 1.0, 2.0]);
let indices = argsort(&a, None, None, None).expect("argsort should succeed");
assert_eq!(indices.to_vec(), vec![1, 2, 0]); // sorted order: [1.0, 2.0, 3.0]