pad_2d

Function pad_2d 

Source
pub fn pad_2d<T>(
    array: ArrayView<'_, T, Ix2>,
    pad_width: ((usize, usize), (usize, usize)),
    pad_value: T,
) -> Array<T, Ix2>
where T: Clone,
Expand description

Pad a 2D array with a constant value

§Arguments

  • array - The input 2D array
  • pad_width - A tuple of tuples specifying the number of values padded to the edges of each axis: ((before_axis_0, after_axis_0), (before_axis_1, after_axis_1))
  • pad_value - The value to set the padded elements

§Returns

A new array with padded borders

§Examples

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

let a = array![[1, 2], [3, 4]];

// Pad with 1 row before, 2 rows after, 1 column before, and 0 columns after
let padded = pad_2d(a.view(), ((1, 2), (1, 0)), 0);
assert_eq!(padded.shape(), &[5, 3]);
assert_eq!(padded,
    array![
        [0, 0, 0],
        [0, 1, 2],
        [0, 3, 4],
        [0, 0, 0],
        [0, 0, 0]
    ]
);