Skip to main content

Module indexing

Module indexing 

Source
Expand description

Indexing module for NumRS2 arrays

This module provides comprehensive indexing capabilities for arrays, including:

  • Basic indexing with integer indices
  • Slicing with ranges and steps
  • Boolean (mask) indexing
  • Fancy indexing with index arrays
  • NewAxis and Ellipsis support

§Examples

use numrs2::prelude::*;

// Create a 2D array
let arr = Array::from_vec(vec![1, 2, 3, 4, 5, 6]).reshape(&[2, 3]);

// Basic indexing
let elem = arr.get(&[0, 1]).expect("valid index should succeed");
assert_eq!(elem, 2);

// Slicing
let slice = arr.index(&[IndexSpec::All, IndexSpec::Slice(0, Some(2), None)])
    .expect("valid slice should succeed");
assert_eq!(slice.shape(), vec![2, 2]);

Enums§

IndexSpec
Represents an index specification for a single dimension

Functions§

diag_indices
Return the indices to access the main diagonal of an n-dimensional array.
diag_indices_from
Return the indices to access the main diagonal of an array.
extract
Return the elements of an array that satisfy some condition
indices_grid
Create index arrays for the nth dimension in an n-dimensional grid from shape
ix_
Generate index arrays for fancy indexing
mask_indices
Return the indices to access array elements that satisfy the given condition
put
Set array values using indices
put_along_axis
Put values into array by matching 1D indices along axis
putmask
Set array elements using a mask array
ravel_multi_index
Converts a tuple of index arrays into an array of flat indices
take
Take elements from array along axis using indices
take_along_axis
Take values from array by matching 1D indices along axis
tril_indices
Return the indices for the lower-triangle of an array.
tril_indices_from
Return the indices for the lower-triangle of an array from an existing array.
triu_indices
Return the indices for the upper-triangle of an array.
triu_indices_from
Return the indices for the upper-triangle of an array from an existing array.
unravel_index
Converts a flat index or array of flat indices into a tuple of coordinate arrays