question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

np.roll improvements

See original GitHub issue

Two quick suggestions:

  • add an inplace={False|True} (or perhaps just out, like for the ufuncs).
  • support shifting along multiple axes simultaneously: either allow shift to be an array-like of length equal to the array’s ndim, or allow passing two sequences, shift and axis, of the same length (or allow both).

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:3
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
link89commented, Oct 8, 2019

Is there API that I can use an array as a shift register ? For example,

arr = np.arange(10)
new_data = np.zeros(4)
arr.shift(new_data)
# then arr should become: [4, 5, 6, 7, 8, 9, 0, 0, 0, 0] , the array is left shifted by 4 unit, and new_data is insert to the end of the array

This pattern is very common in real time signal process. I really hope numpy can have such API to reduce unnecessary memory copy.

1reaction
anntzercommented, May 14, 2015

At least in the case where the shift is small compared to the size of the array (and I expect shifts by 1 to be quite common), roll could at least work by allocating a small array equal to the number of shifted elements as temporary storage and do the shifting in place.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fast numpy roll - python - Stack Overflow
Further improvement. For repeated usages, you are better off creating the full linear indices and then using np.take to extract the rolled ......
Read more >
numpy.roll — NumPy v1.24 Manual
Supports rolling over multiple dimensions simultaneously. Examples. >>> x = np.arange(10) >>> np.roll(x, 2) array([8, 9, 0, 1, 2, 3, 4, 5, 6, ......
Read more >
ncempy.algo package - openNCEM Documentation
Returns: List of filtered points, two column array. Return type: np.ndarray. ncempy.algo.distortion. optimize_center ...
Read more >
numpy.roll() in Python - GeeksforGeeks
roll () function rolls array elements along the specified axis. Basically what happens is that elements of the input array are being shifted....
Read more >
Optimizing very simple piece of “Game of Life” code by taking ...
Benchmarking this we see a significant improvement in speed (x 180): ... N = np.roll(Z,1,axis=1) + np.roll(Z,-1,axis=1) + np.roll(Z,1,axis=0) + np.roll(Z,-1 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found