A very basic example of how to pass arrays between python and c++ using cython
Clone or download
Latest commit 0923d8a Oct 13, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore gitignore file Aug 13, 2015
README.md Update README.md Oct 12, 2018
Rectangle.cpp initial Apr 30, 2015
Rectangle.h initial Apr 30, 2015
python_test.py Very minor cleaning up Oct 12, 2018
rect.pyx initial Apr 30, 2015
setup.py initial Apr 30, 2015


Python c++ interface example

This code illustrates how simple it is to pass n-dimensional (or in this case 2D) numpy arrays from python to c++ vectors and back.

Allowing computationally expensive code to be easily written in c++ and linked to high level python code.

This code is a small adaption from the Cython standard example (Wrapping c++) to also include the 2D numpy example


  • numpy
  • Cython

Rectangle.cpp and Rectangle.h is a an example c++ class to be wrapped

This is wrapped using cython with an interface file rect.pyx and compiled using setup.py in the standard cython way using the command:

Compiling the code:

python setup.py build_ext --inplace

Running the code:

python python_test.py