2

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

askewchan
  • 45,161
  • 17
  • 118
  • 134
West1234
  • 189
  • 14
  • Suppose you have 1000 elements, the first round you sample 100. In the second round, do you sample 100 from 900 or 90 from 900? – CT Zhu Sep 14 '13 at 01:50
  • @CTZhu Oh, now I understand your comment on my question. Obviously I assumed OP meant 10% of the total each time, not of the remainder ... this avoids zeno's paradox, but who knows what the application is. – askewchan Sep 14 '13 at 03:46
  • 1
    yes sorry 10% of the total , see comment below. thanks! – West1234 Sep 14 '13 at 11:54

2 Answers2

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:]
Tzach
  • 12,889
  • 11
  • 68
  • 115
1

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.

askewchan
  • 45,161
  • 17
  • 118
  • 134
  • 1
    I am not sure this is correct. The result of this implementation would mean the probability of being sampled are the same in each of the 10 10% segments. But in the original question, the first set has p=0.1, the second has p=(1-0.1)*0.1=0.09 and so on. The probability is not equal across all 10 segments. – CT Zhu Sep 14 '13 at 01:27
  • No, each particle has equal chance of being in each division, regardless of the order of the sampling. Otherwise the probability does not add to 1. – askewchan Sep 14 '13 at 03:13
  • I have 50 XYZC. I need A random 10% of those numbers eg 5 , I perform a calculation on the C for these 5 numbers , then i need another different 5 numbers, perform a calculation on there C . Then i need another different 5 numbers, perform a calculation on there C. And do this until I have no numbers left. Everytime I do a calculation on the C i need it to change on the total 50XYZC – West1234 Sep 14 '13 at 11:52
  • My application has to do with a point cloud simplification method im working on – West1234 Sep 14 '13 at 11:53