[Numpy-discussion] neighborhood iterator

Nadav Horesh nadavh@visionsense....
Mon Nov 23 08:12:30 CST 2009


Thank you, this is a start. I seems that there are more issues to resolve. I am trying to make a general frame that would enable one to write filters using this iterator.


   Nadav

-----Original Message-----
From: numpy-discussion-bounces@scipy.org on behalf of David Warde-Farley
Sent: Mon 23-Nov-09 03:21
To: Discussion of Numerical Python
Subject: Re: [Numpy-discussion] neighborhood iterator
 

On 22-Nov-09, at 12:50 PM, Nadav Horesh wrote:

>
> I wonder if the neighbourhood iterator can be used as a more  
> efficient replacement for ndimage.generic_filter. Is there a way to  
> use it from cython?

Yes, using the NumPy C API, called like any other C function is from  
Cython. Something like:

######################

import numpy as np
cimport numpy as np

cdef extern from "numpy/arrayobject.h":
     object PyArray_NeighborhoodIterNew(object iter, np.npy_intp bounds,
                                       int mode, object, np.ndarray  
fill_value)
     int PyArrayNeighborhoodIter_Next(object iter)
     int PyArrayNeighborhoodIter_Reset(object iter)

######################

should do the trick.

Note that you'll need to call np.import_array() before using any of  
these functions to initialize the C API, I think.

David
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/ms-tnef
Size: 3261 bytes
Desc: not available
Url : http://mail.scipy.org/pipermail/numpy-discussion/attachments/20091123/bcac2dde/attachment.bin 


More information about the NumPy-Discussion mailing list