[SciPy-user] Simple combinatorics with Numpy

T J tjhnson at gmail.com
Tue Oct 21 17:26:21 EDT 2008


On Tue, Oct 21, 2008 at 11:18 AM, Michael <mnandris at blueyonder.co.uk> wrote:
> On Tue, 2008-10-21 at 12:00 -0500, scipy-user-request at scipy.org wrote:
>
>>  For that, I need to *enumerate* all the possible unordered
>> samples of size 3 that can be drawn from x, i.e.,
>>
>>   (1,1,1), (1,1,3), (1,1,5), (1,1,8), (1,3,3), (1,5,5), ...
>>   [there are comb(4+3-1,3)=20 different samples]
>
>>>> from scipy.misc import comb
>>>> comb(6,3)
> array(20.000000000000014)
>
> To get the actual samples, there is a recipe in the Python Cookbook, 2nd
> edition, p725
>

I could be wrong, but I don't think the recipe provides what the OP is
requesting. The corresponding docstring would be:

''' take n (not necessarily distinct) items, order is irrelevant '''

which is, noticeably, absent from page 725
(http://books.google.com/books?id=Q0s6Vgb98CQC&pg=PA725)



More information about the SciPy-User mailing list