On Wed, Aug 02, 2006 at 04:51:07PM -0400, Mark Heslep wrote: > I need a binary threshold and numpy.where() seems very slow on numpy > 0.9.9.2800: > > python -m timeit -n 10 -s "import numpy as n;a=n.ones((512,512), > n.uint8)*129" > "a_bin=n.where( a>128, 128,0)" > 10 loops, best of 3: 37.9 msec per loop
Using numpy indexing brings the time down by a factor of 10 or so: In [46]: timeit b = N.where(a>128,128,0) 10 loops, best of 3: 27.1 ms per loop In [47]: timeit b = (a > 128).astype(N.uint8) * 128 100 loops, best of 3: 3.45 ms per loop Binary thresholding can be added to ndimage easily, if further speed improvement is needed. Regards Stéfan ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Numpy-discussion mailing list Numpy-discussion@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/numpy-discussion