[Numpy-discussion] Multidimension array access in C via Python API

Antoine Pitrou solipsis at pitrou.net
Tue Apr 5 13:24:30 EDT 2016


On Tue, 5 Apr 2016 08:39:39 -0700 (MST)
mpc <matt.p.conte at gmail.com> wrote:
> This is the reason I'm doing this in the first place, because I made a pure
> python version but it runs really slow for larger data sets, so I'm
> basically rewriting the same function but using the Python and Numpy C API,
> but if you're saying it won't run any faster then maybe I'm going at it the
> wrong way. (Why use the C function version if it's the same speed anyway?)

The Python and Numpy C API are generally not very user-friendly
compared to Python code, even hand-optimized.

Cython will let you write code that looks quite close to normal Python
code, but with additional annotations for better performance.  Or you
can try Numba, a just-in-time compiler for scientific code that
understand Numpy arrays:
http://numba.pydata.org/

Regards

Antoine.





More information about the NumPy-Discussion mailing list