[SciPy-user] SciPy-user Digest, Vol 70, Issue 6

Ranjit Chacko rjchacko@gmail....
Thu Jun 4 10:47:26 CDT 2009

Thanks David, that's kind of what I figured but I wanted to make sure I
wasn't missing anything. It does make a difference to not use the constantly
updated array, so it seems weave is the only way to really speed this up.
Is there a built in function for doing this circular padding?

> ------------------------------
> Message: 4
> Date: Wed, 3 Jun 2009 14:48:53 -0700 (PDT)
> From: David Baddeley <david_baddeley@yahoo.com.au>
> Subject: Re: [SciPy-user] can this be vectorized?
> To: scipy-user@scipy.org
> Message-ID: <42904.26504.qm@web33003.mail.mud.yahoo.com>
> Content-Type: text/plain; charset=utf-8
> Hi Ranjit,
> I think this is going to be hard to vectorise your code as it is, as the
> array s (which is used to calculate field) changes within the loop.
> r = numpy.random.random((self.N,self.N))
> field= scipy.ndimage.convolve(s, numpy.array([[0,1,0],[1,0,1],[0,1,0]]),
> 'same')
> boltzmann_factor=numpy.exp(-beta*field*s)
> s = s*2*(0.5 - (boltzmann_factor>r))
> would give you similar results with a few subtle differences (the 'field'
> is calculated with the initial s rather than the constantly updated s) which
> may or may not be important depending on how large you expect your boltzmann
> factor to be. Also note that the convolution the way I've written it doesn't
> wrap at the edges - you could achieve this by circularly padding s before
> the convolution and then cropping back down to the original size.
> cheers,
> David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20090604/0518a5a6/attachment.html 

More information about the SciPy-user mailing list