I have the following bumpy array:
y =
array([[0],
[2],
[0],
[1],
[0],
[1],
[1],
[1],
[0],
[0],
[2],
[2],
[1],
[2]])
I want to generate 3 lists of non-overlapping indices of rows of y
as follows:
list_1 = 70% of rows
list_2 = 15% of rows
list_3 = 15% of rows
I know how to generate a single list, e.g. list_1
:
import numpy as np
list_1 = [np.random.choice(np.where(y == i)[0], size=n_1, replace=False) for i in np.unique(y)]
where n_1
is equal to the number of rows that correspond to 70% of all rows. In the above example of y
there are totally 14 rows. It means that 70% of 14 rows is equal to 9 (rounded down to 9). Therefore n_1
would be equal to 9.
However, I don't know how to generate the rest of lists (list_2
and list_3
), so that they do not overlap with the row indices in list_1
.