[Numpy-discussion] the neighbourhood of each element of an array

2007-02-23 Thread joris
Hi, Given a (possibly masked) 2d array x, is there a fast(er) way in Numpy to obtain the same result as the following few lines? d = 1 # neighbourhood 'radius' Nrow = x.shape[0] Ncol = x.shape[1] y = array([[x[i-d:i+d+1,j-d:j+d+1].ravel() for j in range(d,Ncol-d)]

Re: [Numpy-discussion] the neighbourhood of each element of an array

2007-02-23 Thread Francesc Altet
A Divendres 23 Febrer 2007 17:38, [EMAIL PROTECTED] escrigué: > Hi, > > Given a (possibly masked) 2d array x, is there a fast(er) way in Numpy to > obtain the same result as the following few lines? > > d = 1 # neighbourhood 'radius' > Nrow = x.shape[0] > Ncol = x.s

Re: [Numpy-discussion] the neighbourhood of each element of an array

2007-02-23 Thread Bryan Cole
On Fri, 2007-02-23 at 17:38 +0100, [EMAIL PROTECTED] wrote: > Hi, > > Given a (possibly masked) 2d array x, is there a fast(er) way in Numpy to > obtain > the same result as the following few lines? > > d = 1 # neighbourhood 'radius' > Nrow = x.shape[0] > Ncol =

Re: [Numpy-discussion] the neighbourhood of each element of an array

2007-02-23 Thread Zachary Pincus
Scipy's ndimage module has a function that takes a generic callback and calls it with the values of each neighborhood (of a given size, and optionally with a particular "mask" footprint) centered on each array element. That function handles boundary conditions, etc nicely. Unfortunately, I'm

Re: [Numpy-discussion] the neighbourhood of each element of an array

2007-02-23 Thread Pierre GM
On Friday 23 February 2007 14:53:05 Zachary Pincus wrote: > Scipy's ndimage module has a function that takes a generic callback > and calls it with the values of each neighborhood (of a given size, > and optionally with a particular "mask" footprint) centered on each > array element. That function

Re: [Numpy-discussion] the neighbourhood of each element of an array

2007-02-25 Thread joris
Thanks for all the useful comments. Some feedback about the improved version of my code snippet. For a 40x40 matrix and d=1 the new version is 44 times faster, and for d=2 it's 27 times faster. For my astronomical images (typical 2000x2000) the new version saves my day. # improved version d = 1 N