Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #36625
| Date | 2013-01-11 14:36 +0000 |
|---|---|
| From | MRAB <python@mrabarnett.plus.com> |
| Subject | Re: Multiple disjoint sample sets? |
| References | <roy-7E69C0.09152911012013@news.panix.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.400.1357915022.2939.python-list@python.org> (permalink) |
On 2013-01-11 14:15, Roy Smith wrote: > I have a list of items. I need to generate n samples of k unique items > each. I not only want each sample set to have no repeats, but I also > want to make sure the sets are disjoint (i.e. no item repeated between > sets). > > random.sample(items, k) will satisfy the first constraint, but not the > second. Should I just do random.sample(items, k*n), and then split the > resulting big list into n pieces? Or is there some more efficient way? > > Typical values: > > len(items) = 5,000,000 > n = 10 > k = 100,000 > I don't know how efficient it would be, but couldn't you shuffle the list and then use slicing to get the samples?
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Multiple disjoint sample sets? Roy Smith <roy@panix.com> - 2013-01-11 09:15 -0500 Re: Multiple disjoint sample sets? MRAB <python@mrabarnett.plus.com> - 2013-01-11 14:36 +0000 Re: Multiple disjoint sample sets? Dave Angel <d@davea.name> - 2013-01-11 10:14 -0500 Re: Multiple disjoint sample sets? Peter Otten <__peter__@web.de> - 2013-01-13 11:16 +0100
csiph-web