[wxpython-users] Fast(er) pixel level access
Christopher Barker
Chris.Barker at noaa.gov
Sat May 3 17:25:42 PDT 2008
Folkert Boonstra wrote:
> Just an update on how far i got with getting it faster.
> Replacing loops with list comprehensions is a major enhancement:
I'm a bit surprised -- I thought list comprehensions gave you almost the
same byte code. I learn something new every day.
Anyway, you can easily get a 10X or so speed up for this kind of thing
with numpy -- it really is the tool for the job, it's well worth learning.
on further examination:
def applyRule(self, rule):
# Apply the rule
xdim = ydim = [d for d in range(DIM) if d>0 and d<(DIM-1)]
if xdim = ydim, why make two? though they are references to the same
thing anyway. (of course, you may be planning to generalize this to when
x does not equal y)
and: [d for d in range(DIM) if d>0 and d<(DIM-1)] is the same as:
range(1,DIM-1)
Let Python work for you!
Still, if you can make your rule function just take the img array, and
process it with numpy tools, it will be much faster (less code to get
wrong, too) -- trust me on this.
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
More information about the wxpython-users
mailing list