NumPy loop efficiency

Sébastien de Menten sdementen at hotmail.com
Fri Mar 30 11:12:14 CEST 2001


Hi,

I was wondering if writing the following statement with NumPy arrays z,a,b
and c:
z = a + b + c
translates into one loop like
for (i in indices)
    z[i] = a[i]+b[i]+c[i]

or two loops
for (i in indices)
    t[i]=a[i]+b[i]
    z[i]=t[i]+c[i]

And if
a[:]=cos(a)+sin(a)
creates temporary variables or assigns directly the result (like
a[i]=cos(a[i])+sin(a[i])

I guess I have too many optimistic expectations...

TX.
Seb





More information about the Python-list mailing list