pad_array

Function pad_array 

Source
pub fn pad_array<T, D>(
    input: &Array<T, D>,
    pad_width: &[(usize, usize)],
    mode: &str,
    constant_value: Option<T>,
) -> Result<Array<T, D>, String>
Expand description

Pad an array with values according to the specified mode.

§Arguments

  • input - Input array
  • pad_width - Width of padding in each dimension (before, after)
  • mode - Padding mode: constant, “edge”, “linear_ramp”, “maximum”, “mean”, “median”, “minimum”, “reflect”, “symmetric”, “wrap”
  • constant_value - Value to use for constant padding (only used for “constant” mode)

§Returns

  • Padded array

§Examples

// Example with a 1D array
use scirs2_core::utils::pad_array;
use ndarray::{Array1, array};

let arr = array![1.0, 2.0, 3.0];
let padded = pad_array(&arr, &[(1, 2)], "constant", Some(0.0)).unwrap();
assert_eq!(padded.shape(), &[6]);
assert_eq!(padded, array![0.0, 1.0, 2.0, 3.0, 0.0, 0.0]);

§Errors

Returns an error if the input array is 0-dimensional, if pad_width length doesn’t match input dimensions, or if the padding mode is unsupported for the given array dimensionality.