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
- High-Performance Array Operations with Cython | Set 2
- Cython to Wrap Existing C Code
- Find the number of operations required to make all array elements Equal
- Arithmetic Operations on Images using OpenCV | Set-2 (Bitwise Operations on Binary Images)
- Operations on Python Counter
- Arithmetic operations using OpenCV | Python
- Python: Operations on Numpy Arrays
- numpy matrix operations | ones() function
- numpy matrix operations | eye() function
- numpy string operations | less() function
- Python | Boolean List AND and OR operations
- numpy string operations | lstrip() function
- numpy string operations | index() function
- numpy string operations | find() function
- numpy string operations | count() 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 email@example.com. 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.