where_condition

Function where_condition 

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

Select elements from an array where a condition is true

§Arguments

  • array - The input array
  • condition - A function that takes a reference to an element and returns a bool

§Returns

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

§Examples

use ndarray::array;
use scirs2_core::ndarray_ext::where_condition;

let a = array![[1, 2, 3], [4, 5, 6]];
let result = where_condition(a.view(), |&x| x > 3).unwrap();
assert_eq!(result.shape(), &[3]);
assert_eq!(result[0], 4);
assert_eq!(result[1], 5);
assert_eq!(result[2], 6);