-
Book Overview & Buying
-
Table Of Contents
NumPy Essentials
By :
In this section, we will create a function to square all the values of the NumPy Array. The aim here is to demonstrate how to get a NumPy Array in C and then iterate over it. In a real-world scenario, this can be done in an easier way using a map or by vectorizing a square function. We are using the same PyArg_ParseTuple function with the O! format string. This format string has a (object) [typeobject, PyObject *] signature and takes the Python type object as the first argument. Users should go through the official API doc to take a look at what other format strings are permissible and which one suits their needs:
If the passed value does not have the same type, then a TypeError is raised.
The following code snippet explain how to parse the argument using PyArg_ParseTuple.
// Implementation of square of numpy array
static PyObject* square_nparray_func(PyObject* self, PyObject* args)
{
// variable declarations...
Change the font size
Change margin width
Change background colour