The inefficiency comes in the generic iteration and construction of int
objects needed by the builtin sum function. Using the native numarray sum
method on each row is much much faster, summing over the axis directly even
faster still:
t1=time.time()
highEnough=myMat>0.6
greaterPerLine=[x.sum()
As soon as I posted that I realized it's due to the type conversions from True
to 1. For some reason, this
---
myMat=scipy.randn(500,500)
t1=time.time()
highEnough=(myMat>0.6)+0
greaterPerLine=[sum(x) for x in highEnough]
elapsed1=time.time()-t1
print("method 1 took %f seconds"%elapsed1)
---
rem
Hi Everyone,
I'm new to numpy, and I'm finding it hard to predict what is fast in
python/numpy and what is slow. The following seems puzzling: I am doing the
same thing an ugly way and a cleaner way. But the ugly map/lambda/filter
expression is 15x faster than using numpy's internals.
Can anyon