问题
I have a set of points xyz8,
I want to randomly get 10% of points.
Then I want to randomly get 10% of the remaining 90%
Then I want to randomly get 10% of the remaining 70%
etc until all points done
How can I go about doing this?
Any advice is hugely appreciated
回答1:
something like:
import random
l = [1,2,3,4]
random.shuffle(l)
while len(l) > 0:
choice = l[:len(l) / 10]
l = l[len(l) / 10:]
回答2:
I interpret this as you want to split the points into 10 equal-sized segments. You can simply do this by shuffling them and reshaping the list:
np.random.shuffle(points)
points.shape = (10,-1) + points.shape[1:]
Then you can access the first 10% as points[0]
, the second as points[1]
, etc.
This still works for a multidimensional array since shuffle will only shuffle along the first axis.
来源:https://stackoverflow.com/questions/18796191/3d-random-sampling