[SciPy-user] execute function on an array elementwise

Matthieu Brucher matthieu.brucher@gmail....
Mon Apr 7 08:26:09 CDT 2008


Hi,

I think you are looking for numpy.vectorize()
It will not be faster than your own loop, but it will respect the shape of
your array.

Matthieu

2008/4/7, Pieter <pieter.cogghe@gmail.com>:
>
> Hi all,
>
> I guess this is an easy one, but can't seem to find it. Suppose I have
> this function:
>
> def myFunction(x):
>   result = None
>   if x > 3:
>     result = "some value"
>   else:
>     result = "another value"
>   return result
>
> And I want to run it on an array a:
> b = myFunction(a)
>
> which then returns an array with "some value" and "another value". I
> could loop over the array, but I guess there's a better way to do
> this? (something like arrayMagic from Matlab if I'm not mistaken.
>
> thanks a lot,
>
> Pieter
>
>
>
> --
>
> Pieter Cogghe
> Ganzendries 186
> 9000 Gent
> 0487 10 14 21
> _______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
>



-- 
French PhD student
Website : http://matthieu-brucher.developpez.com/
Blogs : http://matt.eifelle.com and http://blog.developpez.com/?blog=92
LinkedIn : http://www.linkedin.com/in/matthieubrucher
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/scipy-user/attachments/20080407/444997be/attachment.html 


More information about the SciPy-user mailing list