boolean_mask_1d

Function boolean_mask_1d 

Source
pub fn boolean_mask_1d<T>(
    array: ArrayView<'_, T, Ix1>,
    mask: ArrayView<'_, bool, Ix1>,
) -> Result<Array<T, Ix1>, &'static str>
where T: Clone + Default,
Expand description

Boolean mask indexing for 1D arrays

§Arguments

  • array - The input 1D array
  • mask - Boolean mask of the same shape as the array

§Returns

A 1D array containing the elements where the mask is true

§Examples

use ndarray::array;
use scirs2_core::ndarray_ext::indexing::boolean_mask_1d;

let a = array![1, 2, 3, 4, 5];
let mask = array![true, false, true, false, true];
let result = boolean_mask_1d(a.view(), mask.view()).unwrap();
assert_eq!(result.len(), 3);
assert_eq!(result[0], 1);
assert_eq!(result[1], 3);
assert_eq!(result[2], 5);