Skip to main content

take_along_axis

Function take_along_axis 

Source
pub fn take_along_axis<T: Clone + Zero>(
    array: &Array<T>,
    indices: &Array<usize>,
    axis: usize,
) -> Result<Array<T>>
Expand description

Take values from array along an axis using indices

§Arguments

  • array - Input array
  • indices - Array of indices to take
  • axis - Axis along which to take values

§Returns

  • Result<Array<T>> - Array with values taken along the specified axis

§Examples

use numrs2::prelude::*;
use numrs2::array_ops::advanced_indexing::take_along_axis;

let arr = Array::from_vec(vec![1, 2, 3, 4, 5, 6]).reshape(&[2, 3]);
let indices = Array::from_vec(vec![0, 2, 1, 0]).reshape(&[2, 2]);
let result = take_along_axis(&arr, &indices, 1).expect("operation should succeed");
// For row 0: takes elements at indices [0, 2] -> [1, 3]
// For row 1: takes elements at indices [1, 0] -> [5, 4]
// Result is [[1, 3], [5, 4]]