[SciPy-user] Finding all combinations of numbers
Sat Jan 12 21:56:18 CST 2008
What you're looking for is called the 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.
From: Roger Herikstad <email@example.com>
Sent: January 12, 2008 7:46 PM
To: SciPy Users List <SciPyfirstname.lastname@example.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?
More information about the SciPy-user