I have the following numpy array y_train:
y_train =
2
2
1
0
1
1
2
0
0
I need to randomly select n (n=2) indices of rows as follows:
n=2
n indices of rows where y=0
n indices of rows where y=1
n indices of rows where y=2
I use the following code:
n=2
idx = [y_train[np.random.choice(np.where(y_train==np.unique(y_train)[I])[0],n)].index.tolist() \
for i in np.unique(y_train).astype(int)]
Error in my real array y_train:
KeyError: '[70798 63260 64755 ... 7012 65605 45218] not in index'