[Numpy-discussion] Fwd: [numpy] ENH: Initial implementation of a 'neighbor' calculation (#303)

Nathaniel Smith njs at pobox.com
Sat Jun 9 17:47:45 EDT 2012

[Manual PR notification]

---------- Forwarded message ----------
From: timcera
Date: Sat, Jun 9, 2012 at 10:13 PM
Subject: [numpy] ENH: Initial implementation of a 'neighbor' calculation (#303)
To: njsmith <njs at pobox.com>

Each element is assigned the result of a function based on it's neighbors.
Neighbors are selected based on a weight array.

It uses the new pad routines to pad arrays if neighboring values are
required that would be off the edge of the input array.

Will be great to have the masked array settled because right now you
can only sort of exclude from the neighborhood using a zero in the
weight array.  Zero or np.IGNORE don't affect np.sum, but functions
like np.mean and np.std would give different answers.  Because of this
my early implementations of neighbor included an optional mask array
along with the weight array, but I decided would be best to wait for
the new masked arrays.

This in some ways could be considered a generalization of a
convolution, and comparison with existing numpy/scipy convolution
results are included in the tests.  The advantage to neighbor is that
any function that accepts a 1-d array, and returns a single result,
can be used instead of convolution only using summation.  The
convolution functions require the weight array to be flipped to get
the same answer as neighbor.

You can merge this Pull Request by running:

 git pull https://github.com/timcera/numpy neighbor

Or you can view, comment on it, or merge it online at:


-- Commit Summary --

* ENH: Initial implementation of a 'neighbor' calculation where the each

-- File Changes --

M numpy/lib/__init__.py (2)
A numpy/lib/neighbor.py (305)
A numpy/lib/tests/test_neighbor.py (278)

-- Patch Links --


Reply to this email directly or view it on GitHub:

More information about the NumPy-Discussion mailing list