[SciPy-User] optimising python numpy snippet
Eric Hermes
ehermes at chem.wisc.edu
Thu Jul 24 14:37:17 EDT 2014
Hello,
A quick and dirty simplification may end up in a bit of a speed boost.
You can eliminate some of the loops and replace them with vector
operations, as below.
for k in xrange(self.pooled_shape[3]):
for l in xrange(self.pooled_shape[4]):
self.pooled[0, :, :, k, l] = numpy.tanh(self.conv_out[0, :, :,
k*3:(k+1)*3, l*3:(l+1)*3].sum((2, 3))/9. + self.b[:, :])
I have left in some extraneous slices (:) for clarity of code.
Eric
On 7/24/2014 12:40 PM, Sai Rajeshwar wrote:
> hi all,
>
> I have written the following for loop statement inn my code.. when
> i profiled it.. i found that it is taking huge amount of time.. can
> any one suggest to make this statement faster
> ----------------------------------------------------------------------------
>
> f*or i in xrange(self.pooled_shape[1]):
> for j in xrange(self.pooled_shape[2]):
> for k in xrange(self.pooled_shape[3]):
> for l in xrange(self.pooled_shape[4]):
> self.pooled[0][i][j][k][l]=math.tanh((numpy.sum(self.conv_out[0][i][j][k*3][l*3:(l+1)*3])+numpy.sum(self.conv_out[0][i][j][k*3+1][l*3:(l+1)*3])+numpy.sum(self.conv_out[0][i][j][k*3+2][l*3:(l+1)*3]))/9.0+self.b[i][j])*
>
> thanks a lot in advance
>
>
> *with regards..*
> *
> *
> *M. Sai Rajeswar*
> *M-tech Computer Technology*
> *IIT Delhi
> ----------------------------------Cogito Ergo Sum---------
> *
>
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
--
Eric Hermes
J.R. Schmidt Group
Chemistry Department
University of Wisconsin - Madison
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20140724/3aff4224/attachment.html>
More information about the SciPy-User
mailing list