[Numpy-discussion] Manipulate neighboring points in 2D array

deb otrov at hush.ai
Sun Dec 30 06:21:38 EST 2012

Thanks Zach for your interest

I was thinking about ndimage.generic_filter when I wrote about generic filter.
For generic_filter I used trivial function that returns .sum() but I can't seem to make the code any faster than it is.

This is the code: http://code.activestate.com/recipes/578390-snowflake-simulation-using-reiter-cellular-automat/
As commenter suggested I thought to try and make it in numpy

Interestingly, the first thing I tried before trying to use numpy was change range() loops with xrange(), as xrange is considered faster and more efficient, but result was that code was twice slower.

Anyway I give up, and concluded that my numpy skills are far below I expected :D

> It's possible that some generic filter operations can be cast in
> terms of pure-numpy operations, or composed out of existing filters
> available in scipy.ndimage. If you can describe the filter operation
> you wish to perform, perhaps someone can make some suggestions.

> Alternately, scipy.ndimage.generic_filter can take an arbitrary
> python function. Though it's not really fast...

More information about the NumPy-Discussion mailing list