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

Emmanuelle Gouillart emmanuelle.gouillart@normalesup....
Mon Dec 1 04:28:46 CST 2008


Hello Timmie,

numpy.vectorize(myfunc) should do what you want.

Cheers,

Emmanuelle

> 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]
>
> ###
>
> The results come out well. But the problem is that this
> way of calculation is very ineffiecent and takes time.
>
> May anyone give me a hint on how I can improve my
> code without having to modify the package I am
> building upon. I do not want to change it a lot because
> I would always have to run behind the chnages in the
> other package.
>
> To summarise:
> How to I make a calculation function array-aware?
>
> Thanks in advance,
> Timmie
>
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>




More information about the Numpy-discussion mailing list