[Numpy-discussion] A surprising result from benchmarking

Dan Becker dbecker@alum.dartmouth....
Sun Mar 11 00:32:10 CST 2007


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)
---

remedies that to some extent.  It is only 20% slower than the map.  Still, there
must be some way for me to make the clean way faster than

greaterPerLine2=map(lambda(x):len(filter(lambda(y):y>0.6,x)),myMat)
  
I appreciate any advice on how to do that.

Thanks again,
Dan









More information about the Numpy-discussion mailing list