Is it possible to systematically slice an 1d array of length m by an interval n in numpy? Say I have a list of 1000 values, could I break that into 10 lists of 100 values easily?
SIice a numpy array based on an interval?
1.3k views Asked by BOUNCE At
2
There are 2 answers
0
On
array_split allows one to split with unequal spacing as well, should this ever meet your needs
ar = np.arange(0, 20, dtype='int')
s = [2, 7, 12, 17]
np.array_split(ar, s)
Out[80]:
[array([0, 1]),
array([2, 3, 4, 5, 6]),
array([ 7, 8, 9, 10, 11]),
array([12, 13, 14, 15, 16]),
array([17, 18, 19])]
You can use both
np.array_split()
andnp.split()
which in fact are the same with a little note (as pernp.array_split()
)From the documentation: