Comparing Bottleneck to NumPy functions
Bottleneck is a set of functions inspired by NumPy and SciPy, but written in Cython with high performance in mind. Bottleneck provides separate Cython functions for each combination of array dimensions, axis, and data type. This is not shown to the end user, and the limiting factor for Bottleneck is to determine which Cython function to execute. Install Bottleneck as follows:
$ pip3 install bottleneck
We will compare the execution times for the numpy.median()
and scipy.stats.rankdata()
functions in relation to their Bottleneck counterparts. It can be useful to determine the Cython function manually before using it in a tight loop or frequently called function.
This program is given in the bn_demo.py
file in this book's code bundle:
import bottleneck as bn import numpy as np import timeit setup = ''' import numpy as np import bottleneck as bn from scipy.stats import rankdata np.random.seed(42) a = np.random.randn(30) ...