Book Image

Python Data Analysis

By : Ivan Idris
Book Image

Python Data Analysis

By: Ivan Idris

Overview of this book

Table of Contents (22 chapters)
Python Data Analysis
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Key Concepts
Online Resources
Index

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 name", func

This...