Issue
I have two numpy arrays x and y, which have length 10,000. I would like to plot a random subset of 1,000 entries of both x and y. Is there an easy way to use the lovely, compact random.sample(population, k) on both x and y to select the same corresponding indices? (The y and x vectors are linked by a function y(x) say.)
Thanks.
Solution
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]
Answered By - Jaime
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.