numpy / numpy/numpy

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

Open
#26,220 5 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
32.8k
Forks
12.8k
Avg merge
1d 7h
Merged PRs (30d)
197

Description

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:

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the np.roll API and review how its current wrapping behavior is implemented. Compare the requested zero and constant-fill examples, then determine the API and behavior changes needed; done means the new option works for positive and negative shifts without changing existing np.roll behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.