Re: [Numpy-discussion] is there an efficient way to get a random set of subsets/combinations?

2012-02-21 Thread Yaroslav Halchenko
Thank you guys for replies!

On Mon, 20 Feb 2012, Christopher Jordan-Squire wrote:
 If you're using numpy 2.0 (the development branch), the function
 numpy.random.choice might do what you're looking for.

yeap -- handy one, although would require manual control over
repetitions lazy me was trying to avoid ;)

On Tue, 21 Feb 2012, Val Kalatsky wrote:
Hi Slava,

Mom, is that you? ;-)

Since your k is only 10, here is a�quickie:
import numpy as np
arr = np.arange(n)
for i in range(k):
� � np.random.shuffle(arr)
� � print np.sort(arr[:p])
If your ever get non-unique entries in a set of k=10 for your n and p,
consider yourself lucky:)

well -- I just thought that there might be an ideal function which in
limit would return all combinations if given large enough k for
reasonably small (n, p)... but indeed I should just put a logic in place
to treat those cases separately.

-- 
=--=
Keep in touch www.onerussian.com
Yaroslav Halchenko www.ohloh.net/accounts/yarikoptic
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] is there an efficient way to get a random set of subsets/combinations?

2012-02-20 Thread Yaroslav Halchenko
Hi to all Numeric  Python experts,

could not think of a mailing list with better fit to my question which might
have an obvious answer:

straightforward (naive) Python code to answer my question would be
something like

import random, itertools
n,p,k=100,50,10  # don't try to run with this numbers! ;)
print random.sample(list(itertools.combinations(range(n), p)), k)

so the goal is to get k (non-repeating) p-subsets of n, where n and p
prohibitively large to first populate the full set of combinations.

Thank you in advance ;-)
-- 
=--=
Keep in touch www.onerussian.com
Yaroslav Halchenko www.ohloh.net/accounts/yarikoptic
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] is there an efficient way to get a random set of subsets/combinations?

2012-02-20 Thread Christopher Jordan-Squire
If you're using numpy 2.0 (the development branch), the function
numpy.random.choice might do what you're looking for.

-Chris

On Mon, Feb 20, 2012 at 8:35 PM, Yaroslav Halchenko
li...@onerussian.com wrote:
 Hi to all Numeric  Python experts,

 could not think of a mailing list with better fit to my question which might
 have an obvious answer:

 straightforward (naive) Python code to answer my question would be
 something like

 import random, itertools
 n,p,k=100,50,10  # don't try to run with this numbers! ;)
 print random.sample(list(itertools.combinations(range(n), p)), k)

 so the goal is to get k (non-repeating) p-subsets of n, where n and p
 prohibitively large to first populate the full set of combinations.

 Thank you in advance ;-)
 --
 =--=
 Keep in touch                                     www.onerussian.com
 Yaroslav Halchenko                 www.ohloh.net/accounts/yarikoptic
 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] is there an efficient way to get a random set of subsets/combinations?

2012-02-20 Thread Val Kalatsky
Hi Slava,

Since your k is only 10, here is a quickie:

import numpy as np
arr = np.arange(n)
for i in range(k):
np.random.shuffle(arr)
print np.sort(arr[:p])

If your ever get non-unique entries in a set of k=10 for your n and p,
consider yourself lucky:)
Val

On Mon, Feb 20, 2012 at 10:35 PM, Yaroslav Halchenko
li...@onerussian.comwrote:

 Hi to all Numeric  Python experts,

 could not think of a mailing list with better fit to my question which
 might
 have an obvious answer:

 straightforward (naive) Python code to answer my question would be
 something like

 import random, itertools
 n,p,k=100,50,10  # don't try to run with this numbers! ;)
 print random.sample(list(itertools.combinations(range(n), p)), k)

 so the goal is to get k (non-repeating) p-subsets of n, where n and p
 prohibitively large to first populate the full set of combinations.

 Thank you in advance ;-)
 --
 =--=
 Keep in touch www.onerussian.com
 Yaroslav Halchenko www.ohloh.net/accounts/yarikoptic
 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion