[Numpy-discussion] optimising single value functions for array calculations

Matthieu Brucher matthieu.brucher@gmail....
Mon Dec 1 04:33:56 CST 2008

2008/12/1 Timmie <timmichelsen@gmx-topmail.de>:
> Hello,
> I am developing a module which bases its calculations
> on another specialised module.
> My module uses numpy arrays a lot.
> The problem is that the other module I am building
> upon, does not work with (whole) arrays but with
> single values.
> Therefore, I am currently forces to loop over the
> array:
> ###
> a = numpy.arange(100)
> b = numpy.arange(100,200)
> for i in range(0,a.size):
>    a[i] = myfunc(a[i])* b[i]
> ###


Safe from using numpy functions inside myfunc(), numpy has no way of
optimizing your computation. vectorize() will help you to have a clean
interface, but it will not enhance speed.

Information System Engineer, Ph.D.
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

More information about the Numpy-discussion mailing list