[Numpy-discussion] Adding a 2D with a 1D array...

Francesc Alted faltet at pytables.org
Thu Sep 10 07:31:28 EDT 2009


A Thursday 10 September 2009 11:43:44 Ruben Salvador escrigué:
> OK. Thanks everybody :D
> But...what is happening now? When executing this code:
>
> print ' .....  object parameters mutation .....'
> print 'np.shape(offspr)', np.shape(offspr)
> print 'np.shape(offspr[0])', np.shape(offspr[0])
> print "np.shape(r)", np.shape(r)
> print "np.shape(offspr_sigma)", np.shape(offspr_sigma)
> a = offspr_sigma * np.random.normal(0, 1, shp_sigma)
> print "np.shape(a)", np.shape(a)
> t4 = clock()
> offspr[...] = r
> offspr += a[:,None]
> t5 = clock() - t4
> print "Pythonic time (no array creation) ==> %.8f seconds" % t5
> t2 = clock()
> offspr = r + a[:,None]
> t3 = clock() - t2
> print "Pythonic time ==> %.8f seconds" % t3
> t = clock()
> for i in range(lambd):
>     offspr[i] = r[i] + a[i]
> t1 = clock() - t
> print "For loop time ==> %.8f seconds" % t1
>
> what I get is
[clip]

What's your definition for offspr?  Please always try to send auto-contained 
code snippets so that other people can better help you.

-- 
Francesc Alted
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20090910/4bbe75d7/attachment.html>


More information about the NumPy-Discussion mailing list