[Numpy-discussion] Taking a large number of dot products at once

Sturla Molden sturla@molden...
Fri Mar 4 08:19:46 CST 2011

Den 04.03.2011 14:55, skrev Sturla Molden:
> or just to write more Pythonic code. We don't need to write FORTRAN in 
> Python, computers are fast.

Don't be afraid of Python containers and for-loops. They are not nearly 
as evil as Matlab's for loops used to be. Also operations like appending 
tend to be O(1) in Python, but often O(N) in Matlab. In Python we don't 
need to preallocate space for a list or stack, and manually hoist it out 
of the loop.

Replacing Python lists, sets, dicts, tuples, etc. with NumPy ndarrays or 
record arrays, and pretending to use FORTRAN or Matlab, can be silly. 
Try it before you conclude it's slow and write twice the amount of code 
you need to. Those coming to NumPy from Matlab might not be aware of 
this. It's never wise to write Matlab in Python, we have Matlab for 
that. Nor is it wise to write Python in Matlab -- the Pythonic style is 
generally the one recommended against when using Matlab. Speed 
considerations are very different.

Another realated sillyness I've seen is using NumPy record arrays to 
avoid Python dicts. A record array is nice if we need to memory map a 
file with an underlying C struct,  and parse structured binary data. But 
using it to avoid Python dicts is dumb -- all Python objects have a 
__dict__ anyway. I think it's the Matlab way of solving problems that 
make some NumPy users think like this. We are programming Python, not 

Sorry for the rant.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20110304/13894d58/attachment.html 

More information about the NumPy-Discussion mailing list