Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
reference: http://scipy-lectures.github.io/advanced/interfacing_with_c/interfacing_with_c.html
           http://wiki.scipy.org/Cookbook/C_Extensions/NumPy_arrays

to build:

python setup.py build_ext --inplace

to run:

>>> import numpy_in_c
>>> help (numpy_in_c)

>>> import numpy as np

>>> a = np.arange(20, dtype=np.float64)
>>> a.shape = (4,5)
>>> print a
[[  0.   1.   2.   3.   4.]
 [  5.   6.   7.   8.   9.]
 [ 10.  11.  12.  13.  14.]
 [ 15.  16.  17.  18.  19.]]

>>> b = numpy_in_c.example(a)
>>> print b
[[   0.    1.    4.    9.   16.]
 [  25.   36.   49.   64.   81.]
 [ 100.  121.  144.  169.  196.]
 [ 225.  256.  289.  324.  361.]]




Note that directly accessing the fields in the PyArrayObject struct is
deprecated, and there will be a warning issued.