NumPy loop efficiency

Konrad Hinsen hinsen at
Fri Mar 30 14:11:31 CEST 2001

Carlos Alberto Reis Ribeiro <cribeiro at> writes:

> The intermediate array is not really needed, but the python expresion 
> evaluator have no way to know it. However, something like the ufuncs could 
> be used. For instance, something like this could be done (the names are 
> just examples):

Something like that (but not entirely) is possible but little known:

     Numeric.add(a, b, c)

does the same as

     c = a + b

but storing the result in the preallocated array c (which must of
course have the right dimensions). And c can well be a or b, in which
case the data is overwritten. By using only these functions, many
temporary arrays can be avoided, but at the cost of producing
unreadable code.
Konrad Hinsen                            | E-Mail: hinsen at
Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-
Rue Charles Sadron                       | Fax:  +33-
45071 Orleans Cedex 2                    | Deutsch/Esperanto/English/
France                                   | Nederlands/Francais

More information about the Python-list mailing list