0

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)

1
  • 2
    [x[i::10] for i in range(10)] Commented Oct 4, 2022 at 13:42

1 Answer 1

1

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])


Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.