[SciPy-user] Finding all combinations of numbers
David Warde-Farley
dwf at cs.toronto.edu
Sat Jan 12 22:56:18 EST 2008
What you're looking for is called the power set:
http://en.wikipedia.org/wiki/Power_set
I don't know offhand if Scipy would include this (it seems a bit out of scope) but there is a simple recursive (and slightly more complcated iterative) algorithm for computing the power set, the pseudocode for which can be found easily on the web (article above is a good starting point).
Note that strictly speaking the power set of S (set of all subsets of S) cobtains the empty set, and most algorithms for computing the power set rely on this, however it should be easy to remove the not so useful empty case once you're done.
Cheers,
DWF-----Original Message-----
From: Roger Herikstad <roger.herikstad at gmail.com>
Sent: January 12, 2008 7:46 PM
To: SciPy Users List <SciPy-user at scipy.org>
Subject: [SciPy-user] Finding all combinations of numbers
Hi all, I was wondering if there is a functions in scipy for generating all
possible combinations of a set of numbers? E.g [1,2,3] ->
[[1,2],[1,3],[2,3],[1,2,3]]. Basically I'm looking for a function that can
generate all unique pairs, triplets, quadruples, etc, etc. Any thoughts?
~ Roger
More information about the SciPy-User
mailing list