O'Reilly logo

Practical Data Science Cookbook by Abhijit Dasgupta, Benjamin Bengfort, Sean Patrick Murphy, Tony Ojeda

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Rewriting simple functions with NumPy

With the impressive test results from the previous recipe, this recipe will focus on rewriting some of the smaller functions in asa.py using NumPy. We will start with the smaller, more manageable find_neighbor_indices function as a prototype for changes to the main function.

Getting ready

To prepare for this recipe, we will create a copy of asa.py and call it asa_np_v1.py.

How to do it…

The following steps will walk you through this recipe:

  1. First, add the @profile decorator to the find_neighbor_indices function in asa.py:
    @profile
    def find_neighbor_indices(points, radii, probe, k):
    
  2. We will use line_profile to benchmark the original find_neighbor_indices function:
    python kernprof.py -l asa_np_v1.py "1R0R.pdb"
    

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required