Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23247

Numpy, grouping every N continuous element?

$
0
0

I would like to extract groups of every N continuous elements from an array. For a numpy array like this:

a = numpy.array([1,2,3,4,5,6,7,8])

I wish to have (N=5):

array([[1,2,3,4,5],       [2,3,4,5,6],       [3,4,5,6,7],       [4,5,6,7,8]])

so that I can run further functions such as average and sum. How do I produce such an array?


Viewing all articles
Browse latest Browse all 23247

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>