[Numpy-discussion] Advice on converting Numarray C extension?

Perry Greenfield perry at stsci.edu
Mon Jun 29 18:01:51 EDT 2009

Hi Russell,

Have you looked at the example in our interactive data analysis  
tutorial where we compute radial profiles in Python? It's not as fast  
as C because of the sort, but perhaps that's fast enough for your  
purposes. I wasn't sure if you had already seen that approach or not.  
(I think it is in the 3rd chapter, but I can look it up if you need me  


On Jun 29, 2009, at 5:03 PM, Russell E. Owen wrote:

> I have an old Numarray C extension (or, rather, a Python package
> containing a C extension) that I would like to convert to numpy
> (in a way that is likely to be supported long-term).
> Options I have found include:
> - Use the new numpy extension. This seems likely to be fast and
> future-proof. But I am finding the documentation slow going. Does  
> anyone
> know of a simple example (e.g. read in an array, create a new array)?
> - Use the Numarray compatible C API. Simple (and takes advantage of  
> the
> nice Numarray tutorial example for documentation), but will this be
> supported in the long term?
> - Switch to ctypes. Simple in concept. But I'm wondering if I can get
> distutils to build the resulting package.
> - Use SWIG. I have some experience with it, but not with numpy arrays.
> - Use Cython to replace the C code. No idea if this is a long-term
> supported package.
> Another option is to try to rewrite in pure python. Perhaps the numpy
> indexing is sophisticated enough to allow an efficient solution. The C
> extension computes a radial profile from a 2-d masked array:
> radProf(r)= sum of all unmasked pixels at radius r about some
> specified center index
> I can easily generate (and cache) a 2-d array of radius index, but  
> is it
> possible to use that to efficiently generate the desired sum?
> Any opinions?
> -- Russell
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion

More information about the NumPy-Discussion mailing list