Reputation: 621
For a data set, x, of dimensions (n, m):
n = 50
m = 100
x = np.random.random((n,m))
I would like to split it into y subsets, so that for 10 subsets it would be based on the indices:
index_1 = [0, 10, 20, 30, 40]
index_2 = [1, 11, 21, 31, 41]
...
index_9 = [8, 18, 28, 38, 48]
index_10 = [9, 19, 29, 39, 49]
I know that np.array_split()
or np.split()
can be used to subset based on the wanted number of subsets, and i would like a similar output (list of np.ndarrays)
Upvotes: 0
Views: 50
Reputation: 96
you can use this as a reference and modify to your needs.
import numpy as np
n = 50
m = 100
mylist = np.random.randint(n, size=m)
for i in range(0, len(mylist), 5):
print(mylist[i:i+5])
Upvotes: 1