简体   繁体   中英

how to create a c function of `numpy.array`?

I was looking at this tutorial: https://docs.scipy.org/doc/numpy-1.13.0/user/c-info.ufunc-tutorial.html and understood how to write c functions of scalar arguments (which return, say, a double ) and broadcastable functions that accept as argument numpy.array s and return another numpy.array by default.

How can I write a c function that takes one or more numpy.array s and return a scalar value, instead?

To write a new Python function (generally) in C, see: https://docs.python.org/2/extending/extending.html

And here is page with an example function (addList) to use as a starting point: http://book.pythontips.com/en/latest/python_c_extension.html#python-c-api

Then, to access function arguments that are numpy arrays, see the Numpy C-API documentation, here: https://docs.scipy.org/doc/numpy-1.13.0/reference/c-api.array.html#array-structure-and-data-access

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM