[Numpy-discussion] vectorizing loops

Gael Varoquaux gael.varoquaux@normalesup....
Fri Oct 26 02:31:44 CDT 2007


On Fri, Oct 26, 2007 at 01:56:26AM -0500, Robert Kern wrote:
> Gael Varoquaux wrote:
> > On Thu, Oct 25, 2007 at 04:16:06PM -0700, Mathew Yeates wrote:
> >> Anybody know of any tricks for handling something like

> >> z[0]=1.0
> >> for i in range(100):
> >>     out[i]=func1(z[i])
> >>     z[i+1]=func2(out[i])

> > Something like:

> > z[0] = 1.
> > out = func1(z)
> > z[1:] = func2(out[:-1])

> No, that doesn't work. The way you have it, for each i>0,

>   z[i] = func2(func1(0))

> What Matthew wants is this

>   z[0] = 1.0
>   z[1] = func2(func1(1.0))
>   z[2] = func2(func1(func2(func1(1.0))))

Yes, obviously. Sorry for being dense.

I can't see a fast way of doing this appart in Python.

Gaël


More information about the Numpy-discussion mailing list