[Numpy-discussion] iterate over multiple arrays
Olivier Delalleau
shish@keba...
Sat Oct 1 12:34:44 CDT 2011
It'll work, it is equivalent to the suggestion I made in my previous post
with the f_inplace wrapper function (and it has the same drawback that numpy
will allocate temporary memory, which wouldn't be the case if f was working
in-place directly, by implementing it as "arr *= 2").
Note that you don't need to write x[:] * 2, you can write x * 2 directly.
-=- Olivier
2011/10/1 David Froger <david.froger@gmail.com>
>
> Thanks everybody for the different solutions proposed, I really appreciate.
> What about this solution? So simple that I didn't think to it...
>
> import numpy as np
> from numpy import *
>
> def f(arr):
> return arr*2
>
> a = array( [1,1,1] )
> b = array( [2,2,2] )
> c = array( [3,3,3] )
> d = array( [4,4,4] )
>
> for x in (a,b,c,d):
> x[:] = x[:]*2
> #instead of: x = x*2
>
> print a
> print b
> print c
> print d
> --
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20111001/37a4fbad/attachment.html
More information about the NumPy-Discussion
mailing list