Hi, Does anyone know why there is an order of magnitude difference in the speed of numpy's array.sum() function depending on the axis of the matrix summed? To see this, import numpy and create a big array with two rows: >>> import numpy >>> a = numpy.ones([2,1000000], 'f4') Then using ipython's timeit function: Time (ms) sum(a) 20 a.sum() 9 a.sum(axis=1) 9 a.sum(axis=0) 159 numpy.dot(numpy.ones(a.shape[0], a.dtype), a) 15 This last one using a dot product is functionally equivalent to a.sum(axis=0), suggesting that the slowdown is due to how indexing is implemented in array.sum(). Cheers Stephen P.S. I am using the following versions of Python and numpy: >>> numpy.__version__ '1.0.1' >>> sys.version '2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)]' |
_______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion