boolean_mask_2d

Function boolean_mask_2d 

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

Boolean mask indexing for 2D arrays

§Arguments

  • array - The input 2D 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_2d;

let a = array![[1, 2, 3], [4, 5, 6]];
let mask = array![[true, false, true], [false, true, false]];
let result = boolean_mask_2d(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);