Skip to main content

mask_select

Function mask_select 

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

Filter an array using a boolean mask

§Arguments

  • array - The input 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 crate::ndarray::array;
use scirs2_core::ndarray_ext::mask_select;

let a = array![[1, 2, 3], [4, 5, 6]];
let mask = array![[true, false, true], [false, true, false]];
let result = mask_select(a.view(), mask.view()).expect("Operation failed");
assert_eq!(result.shape(), &[3]);
assert_eq!(result[0], 1);
assert_eq!(result[1], 3);
assert_eq!(result[2], 5);