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:
$ pip 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. Print the name of the Bottleneck median()
function as follows:
func, _ = bn.func.median_selector(a, axis=0) print "Bottleneck median func name", func
For the rankdata()
function, we can do the following:
func, _ = bn.func.rankdata_selector(a, axis=0) print "Bottleneck rankdata func...