Although libraries like NumPy can perform high-performance array processing functions to operate on arrays. But Cython can also work really well. But how ?
Code #1 : Cython function for clipping the values in a simple 1D array of doubles
work.py file is required to compile and build the extension.
Code #2 :
After performing the task above, now we can check the working of resulting function clips arrays, with many different kinds of array objects.
Code #3 : Working of Clipping Array.
Array : array('d', [1.0, -3.0, 4.0, 7.0, 2.0, 0.0]) Clipping array : array('d', [1.0, 1.0, 4.0, 4.0, 2.0, 1.0]) arr2 : [-9.55546017, 7.45599334, 0.69248932, ..., 0.69583148, -3.86290931, 2.37266888] arr3 : array([ 0., 0., 0., ..., 0., 0., 0.]) Clipping arr3 : [-5., 5., 0.69248932, ..., 0.69583148, -3.86290931, 2.37266888] Minimum in arr3 : 5.0 Maximum in arr3 : 5.0
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- High-Performance Array Operations with Cython | Set 2
- Cython to Wrap Existing C Code
- Facts about Cython Programming Language
- Arithmetic Operations on Images using OpenCV | Set-2 (Bitwise Operations on Binary Images)
- Python set operations (union, intersection, difference and symmetric difference)
- Arithmetic Operations on Images using OpenCV | Set-1 (Addition and Subtraction)
- Python | Morphological Operations in Image Processing (Opening) | Set-1
- Python | Morphological Operations in Image Processing (Closing) | Set-2
- Python | Morphological Operations in Image Processing (Gradient) | Set-3
- Common Operations on Fuzzy Set with Example and Code
- Find the number of operations required to make all array elements Equal
- NumPy - Arithmetic operations with array containing string elements
- Image segmentation using Morphological operations in Python
- Python | Math operations for Data analysis
- Python | Arithmetic operations in excel file using openpyxl
- Python | Trigonometric operations in excel file using openpyxl
- numpy string operations | isupper() function
- numpy string operations | istitle() function
- numpy string operations | islower() function
- numpy string operations | lower() function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.