Skip to Content
NumPy Essentials
book

NumPy Essentials

by Jaidev Deshpande, Leo (Liang-Huan) Chin, Tanmay Dutta, Shane Holloway
April 2016
Beginner content levelBeginner
156 pages
3h 23m
English
Packt Publishing
Content preview from NumPy Essentials

Creating an array squared function using Python C-API

The Python function passes a reference to itself as the first argument, followed by real arguments given to the function. The PyArg_ParseTuple function is used to parse values from the Python function to local variables in the C function. In this function, we cast a value to a double, and hence we use d as the second argument. You can see a full list of strings that are accepted by this function at  https://docs.python.org/2/c-api/arg.html .

The final result of the computations is returned using Py_Buildvalue, which takes a similar type of format string to create a Python value from your answer. We use f here, which stands for float, to demonstrate that double and float are treated similarly: ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

SciPy and NumPy

SciPy and NumPy

Eli Bressert
Python Distilled

Python Distilled

David M. Beazley

Publisher Resources

ISBN: 9781784393670Supplemental Content