[Numpy-discussion] Extracting all the possible combinations of a grid

Charles R Harris charlesr.harris at gmail.com
Fri Sep 21 22:15:26 EDT 2007


On 9/21/07, Gary Ruben <gruben at bigpond.net.au> wrote:
>
> Gael Varoquaux wrote:
> > On Fri, Sep 21, 2007 at 02:58:43PM -0600, Charles R Harris wrote:
> >>    I found generators a good approach to this  sort of thing:
> >
> >>    for (i,j,k) in triplets(n) :
> >
> > That's what we where doing so far, but in the code itself. The result
> was
> > unbearably slow.
> > I think for our purposes we should build a precalculated table of these
> > nuplets, and then do array calculations on them.
>
> I'm not sure whether this helps, but I have found this generator-based
> recipe <http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/190465>
> very useful in the past. The comment "If you require the complete list
> of permutations, just use the built-in list() operator" may apply to
> your situation,



Not bad for the triplets, I would have thought the cost of recursion would
be greater. The use of lists slows it down a bit for bigger combinations.

In [50]: time for i in xuniqueCombinations(range(100),3) : pass
CPU times: user 0.56 s, sys: 0.02 s, total: 0.58 s
Wall time: 0.57

In [51]: time for i in xuniqueCombinations(range(20),10) : pass
CPU times: user 2.17 s, sys: 0.07 s, total: 2.23 s
Wall time: 2.23

In [52]: time for i in combination(20,10) : pass
CPU times: user 0.96 s, sys: 0.01 s, total: 0.97 s
Wall time: 0.97

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20070921/4971d83c/attachment.html>


More information about the NumPy-Discussion mailing list