[Numpy-discussion] Multidimensional neighbours

Jose Gomez-Dans jgomezdans at gmail.com
Fri Aug 17 08:27:30 EDT 2012


Hi,

On 16 August 2012 19:38, Sebastian Berg <sebastian at sipsolutions.net> wrote:

> Hello,
>
> Just to throw it in, if you do not mind useing scipy, you can use its
> multidimensional correlate method instead:
>

Well, I don't need to count the number of neighbours as in the linked
example. What I wanted to have is easy access to the neighbours of one
cell, so

neighbours = np.array( [GRID[up,:], GRID[down,:], GRID[:,up], GRID[:,down]
, \
        GRID[ix_(up,up)], GRID[ix_(up,down)], GRID[ix_(down,up)] , \
        GRID[ix_(down,down)] ])

That gives me an array of shape (8,)+GRID.shape. neighbours.sum(axis=1) (I
think) would give me the equivalent of scipy.ndimage.correlate (I think),
but I don't necessarily need a sum or a mean value of the neighbours. It's
just that a 3D neigbourhood is 9 +8 +9 = 26 neighbours for each pixel, and
I was wondering whether there was a simpler way of writing it than what I
had in my message, which is likely to have errors.

Thanks!
Jose
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20120817/85558e07/attachment.html>


More information about the NumPy-Discussion mailing list