ENH: Add a non-circular shift function
July 16, 2025
6:45 p.m.
Feature request: Add a non-circular shift function that is similar to [`numpy.roll`](https://numpy.org/doc/stable/reference/generated/numpy.roll.html) but, instead of wrapping elements around, replaces unoccupied entries with a specified fill value. Examples: ```
import numpy as np a = np.arange(1, 6) a array([1, 2, 3, 4, 5]) np.shifted(a, 2) array([0, 0, 1, 2, 3]) np.shifted(a, -2) array([3, 4, 5, 0, 0]) a = np.arange(1, 10).reshape((3, 3)) a array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) np.shifted(a, (1, -2), (0, 1)) array([[0, 0, 0], [3, 0, 0], [6, 0, 0]])
Prior discussion: https://github.com/numpy/numpy/issues/26220
Pull request: https://github.com/numpy/numpy/pull/29389
November 2025
8:34 p.m.
Bumping this for visibility and discussion: https://github.com/numpy/numpy/pull/29389#issuecomment-3430354321
112
Age (days ago)
242
Last active (days ago)
1 comments
1 participants
participants (1)
-
Carlos Martin