Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
This example for using the C-API with NumPy is for python 3.x only --
the interface for python 2.x is different.  Note that this was written
to use the latest API.

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:

python3 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.]]