Hello all,

I'm only two weeks late with this message about my pull request
<https://github.com/numpy/numpy/pull/18707> that adds functions that allow
the user to pad to a target shape, instead of adding a certain amount to
each axis.

For example:

    x = np.ones((3, 3))
    # We want an output shape of (10, 10)
    padded = np.pad_to_shape(x, (10, 10))
    print(padded.shape)
    prints: (10, 10)

Whereas with the current implementation of np.pad you'd need to first
figure out the difference in axis sizes. The proposed function would
perform this step for you. As this function passes to np.pad internally, I
made sure to include the arguments in the signature that np.pad uses for
padding modes.

Finally, I've added a logical extension of this function; pad_to_match,
this takes another array and pads the input array to match.

These calls would be equivalent:

    x = np.ones((3, 3))
    y = np.zeros((10, 10))
    padded_to_shape = np.pad_to_shape(x, y.shape)
    padded_to_match = np.pad_to_match(x, y)

For additional functionality description, I refer to the pull request.

I'm not too familiar with mailing lists, so I hope this is how things work.

Kind Regards,
Mathijs
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@python.org
https://mail.python.org/mailman/listinfo/numpy-discussion

Reply via email to