Python random sample of two arrays, but matching indices
You can use np.random.choice
on an index array and apply it to both arrays:
idx = np.random.choice(np.arange(len(x)), 1000, replace=False)x_sample = x[idx]y_sample = y[idx]
You can use np.random.choice
on an index array and apply it to both arrays:
idx = np.random.choice(np.arange(len(x)), 1000, replace=False)x_sample = x[idx]y_sample = y[idx]