squeeze_2d

Function squeeze_2d 

Source
pub fn squeeze_2d<T>(
    array: ArrayView<'_, T, Ix2>,
    axis: usize,
) -> Result<Array<T, Ix1>, &'static str>
where T: Clone + Zero,
Expand description

Remove a dimension of size 1 from a 2D array, resulting in a 1D array

§Arguments

  • array - The input 2D array
  • axis - The axis to squeeze (0 for rows, 1 for columns)

§Returns

A 1D array with the specified dimension removed

§Examples

use ndarray::array;
use scirs2_core::ndarray_ext::manipulation::squeeze_2d;

let a = array![[1, 2, 3]];  // 1x3 array (1 row, 3 columns)
let b = array![[1], [2], [3]];  // 3x1 array (3 rows, 1 column)

// Squeeze out the row dimension (axis 0) from a
let squeezed_a = squeeze_2d(a.view(), 0).unwrap();
assert_eq!(squeezed_a.shape(), &[3]);
assert_eq!(squeezed_a, array![1, 2, 3]);

// Squeeze out the column dimension (axis 1) from b
let squeezed_b = squeeze_2d(b.view(), 1).unwrap();
assert_eq!(squeezed_b.shape(), &[3]);
assert_eq!(squeezed_b, array![1, 2, 3]);