Velocity Reviews > Python and Combinatorics

# Python and Combinatorics

none
Guest
Posts: n/a

 10-24-2007
Hello,

Is there some package to calculate combinatorical stuff like (n over
k), i.e., n!/(k!(n - k!) ?

I know it can be written in about 3 lines of code, but still...

Thanks,

Ami

mensanator@aol.com
Guest
Posts: n/a

 10-24-2007
On Oct 24, 5:20 pm, none <""atavory\"@(none)"> wrote:
> Hello,
>
> Is there some package to calculate combinatorical stuff like (n over
> k), i.e., n!/(k!(n - k!) ?

Sure, the gmpy module.

>>> import gmpy
>>> for m in xrange(10):

for n in xrange(m+1):
print '%4d' % (gmpy.comb(m,n)),
print

1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28 8 1
1 9 36 84 126 126 84 36 9 1

>
> I know it can be written in about 3 lines of code, but still...
>
> Thanks,
>
> Ami

none
Guest
Posts: n/a

 10-24-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> On Oct 24, 5:20 pm, none <""atavory\"@(none)"> wrote:
>> Hello,
>>
>> Is there some package to calculate combinatorical stuff like (n over
>> k), i.e., n!/(k!(n - k!) ?

>
> Sure, the gmpy module.
>

Excellent, many thanks!

Alan Isaac
Guest
Posts: n/a

 10-25-2007
none wrote:
> Is there some package to calculate combinatorical stuff like (n over
> k), i.e., n!/(k!(n - k!) ?

Yes, in SciPy.
Alan Isaac

>>> from scipy.misc.common import comb
>>> help(comb)

Help on function comb in module scipy.misc.common:

comb(N, k, exact=0)
Combinations of N things taken k at a time.

If exact==0, then floating point precision is used, otherwise
exact long integer is computed.

Notes:
- Array arguments accepted only for exact=0 case.
- If k > N, N < 0, or k < 0, then a 0 is returned.

Gerard Flanagan
Guest
Posts: n/a

 10-26-2007
On Oct 25, 12:20 am, none <""atavory\"@(none)"> wrote:
> Hello,
>
> Is there some package to calculate combinatorical stuff like (n over
> k), i.e., n!/(k!(n - k!) ?
>
> I know it can be written in about 3 lines of code, but still...
>
> Thanks,
>
> Ami

http://probstat.sourceforge.net/

 Thread Tools

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post David Palm Ruby 7 02-18-2010 04:08 PM Nic Python 4 05-16-2006 09:41 AM Xah Lee Perl Misc 5 02-11-2005 10:05 AM Xah Lee Python 7 02-11-2005 10:05 AM Carnosaur C Programming 17 10-31-2003 03:48 PM

Advertisments