[Numpy-discussion] Multidimensional neighbours

Cera, Tim tim at cerazone.net
Thu Aug 16 15:41:09 EDT 2012

I have a pull request for a neighborhood function at
https://github.com/numpy/numpy/pull/303 .   I think IMHO it handles these
problems quite handily.  It does rely on my pad routine that is in Numpy
1.7, so you would need to get the 1.7 beta installed or install the
development branch.

For your example you would just create a weight array, and a function that
returns a scalar value from the collected neighborhood values.

Untested, but workflow is something like:

>>> inputarr = np.random.random(9*9*9)
>>> inputarr = inputarr.reshape((9,9,9))
>>> weight = np.ones((3,3,3))
>>> ans = neighbor(inputarr, weight, np.mean, pad = None)

In place of 'np.mean' you can define your own function - game of life
function for example.

The PR has not had much activity, so if you can review/comment/program that
would be appreciated.

Kindest regards,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20120816/74cf6fc8/attachment.html>

More information about the NumPy-Discussion mailing list