5 ms·
You can absolutely use numpy arrays with C functions using ctypes. Numpy has `numpy.ctypeslib` which takes care of some of the boilerplate involved.
by ali_m 3y ago
You can absolutely use numpy arrays with C functions using ctypes. Numpy has `numpy.ctypeslib` which takes care of some of the boilerplate involved.
- jofer 3y agoYes, you can, but it is easier in cython, and that is one of the key selling points of cython. Nothing wrong with using ctypes. It's the right solution for some things. However, cython is generally easier with numpy than numpy.ctypeslib
- ali_m 3y agoI think ctypes shines when it comes to fast prototyping, since you can iterate on the python bindings without a compilation step. It can also simplify distribution since the bindings can be pure python. Where it's arguably not so good is performance and maintainability.
- jofer 3y agoYeah, I'd agree with that. Ctypes does have advantages for several use cases, and quick iteration is one of those, for sure. It's definitely a good tool to have in your toolbox!