Python and Combinatorics

Discussion in 'Python' started by none, Oct 24, 2007.

  1. none

    none Guest

    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
     
    none, Oct 24, 2007
    #1
    1. Advertising

  2. none

    Guest

    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
     
    , Oct 25, 2007
    #2
    1. Advertising

  3. none

    none Guest

    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!
     
    none, Oct 25, 2007
    #3
  4. none

    Alan Isaac Guest

    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.
     
    Alan Isaac, Oct 25, 2007
    #4
  5. 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/
     
    Gerard Flanagan, Oct 26, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Carnosaur

    combinatorics question

    Carnosaur, Oct 28, 2003, in forum: C Programming
    Replies:
    17
    Views:
    560
    Carnosaur
    Oct 31, 2003
  2. Xah Lee

    [perl-python] combinatorics fun

    Xah Lee, Feb 10, 2005, in forum: Python
    Replies:
    7
    Views:
    397
    bruno modulix
    Feb 11, 2005
  3. Nic

    Python and Combinatorics

    Nic, May 16, 2006, in forum: Python
    Replies:
    4
    Views:
    1,734
    Gerard Flanagan
    May 16, 2006
  4. David Palm
    Replies:
    7
    Views:
    120
    Sergio Bayona
    Feb 18, 2010
  5. Xah Lee

    [perl-python] combinatorics fun

    Xah Lee, Feb 10, 2005, in forum: Perl Misc
    Replies:
    5
    Views:
    144
    bruno modulix
    Feb 11, 2005
Loading...

Share This Page