Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: np.roll: extra argument to pad with zeros or constant #26220

Open
josephernest opened this issue Apr 7, 2024 · 3 comments
Open

ENH: np.roll: extra argument to pad with zeros or constant #26220

josephernest opened this issue Apr 7, 2024 · 3 comments

Comments

@josephernest
Copy link

josephernest commented Apr 7, 2024

Proposed new feature or change:

In many situations, it is required to shift an array (like np.roll) and fill the values with zeros, instead of making the array "loop".

Is there a way to implement this:

x = np.array([1, 2, 3, 4, 5]
np.roll(x, 2, method="constant")   #  [ 0 0 1 2 3 ]   instead of  [ 4 5 1 2 3 ]
np.roll(x, -2, method="constant")  #  [ 3 4 5 0 0 ]  instead of   [ 3 4 5 1 2 ]

?

Example : python numpy roll with padding

Important notes:

@arararz
Copy link

arararz commented Apr 9, 2024

Has this been added yet? If not I can take on this issue

@josephernest
Copy link
Author

It would be interesting @arararz, thanks!

@luxedo
Copy link
Contributor

luxedo commented May 21, 2024

I disagree of this proposal.

The documentation states that:

Roll array elements along a given axis.

Elements that roll beyond the last position are re-introduced at the first.

Furthermore, I think that the name roll is very expressive in it's intent in my opinion.

I'd much prefer the creation of a new function like scipy.ndimage.shift.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants