Skip to main content

sort

Function sort 

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

Sort an array along the given axis

§Parameters

  • array - Array to be sorted
  • 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

Sorted array

§Examples

use numrs2::prelude::*;

let a = Array::from_vec(vec![3.0, 1.0, 4.0, 1.0, 5.0, 9.0]).reshape(&[2, 3]);
let sorted = sort(&a, Some(1), None, None).expect("sort should succeed");
assert_eq!(sorted.get(&[0, 0]).expect("valid index"), 1.0);
assert_eq!(sorted.get(&[0, 1]).expect("valid index"), 3.0);
assert_eq!(sorted.get(&[0, 2]).expect("valid index"), 4.0);