For such expressions you should try numexpr package: It allows the same type of optimisation as Matlab does: run a single loop over the matrix elements instead of repetitive loops and intermediate objects creation.
Nadav > Besides the matlab/numpy comparison, I think that there is an inherent > problem with how expressions are handled, in terms of efficiency. > For instance, k = (m - 0.5)*0.3 takes 52msec average here (2000x2000 array), > while k = (m - 0.5)*0.3*0.2 takes 0.079, and k = (m - 0.5)*0.3*0.2*0.1 > > takes 101msec. > Placing parentheses around the scalar multipliers shows that it seems to have > to do with how expressions are handled, is there sometihng that can >be done > about this so that numpy can deal with expressions rather than single > operations chained by python itself? Maybe I am missing the point as well. ---------------------- Carlos Becker _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion