Skip to content

Equivalent for np.pad #823

@Dimev

Description

@Dimev

Is there an equivalent for np.pad

I'm trying to make a filter for arrays using windows, however the output array is smaller than the input array, which is something I want to avoid. I think this can be solved by padding the input array to be a bit larger before using it.

My code:

let input = Array2::<f32>::zeros((300, 200));
let kernel = array![[0.0625, 0.125, 0.0625], [0.125, 0.25, 0.125], [0.0625, 0.125, 0.0625]];
let output = ndarray::Zip::from(input.windows(kernel.raw_dim()))
	.apply_collect(|window| {
		(&window * &kernel).sum()
	});

assert_eq!(input.shape(), output.shape()); // this fails

I'm new to both rust and ndarray, so there might be an obvious solution I'm missing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions