O'Reilly logo

Mastering Numerical Computing with NumPy by Mert Cuhadaroglu, Umit Mert Cakmak

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

Profiling NumPy code to understand the performance

There are couple of helpful libraries to monitor performance metrics of a given python script. You have already seen the usage of cProfile library. This section will introduce vprof which is visual profiler library.

It will provide you runtime statistics and memory utilization of a given python program.

1D clustering function from Chapter 5, Clustering Clients of Wholesale Distributor Using NumPy, will be used here and following code snippet should be saved to a file named to_be_profiled.py:

import numpy as npX = np.array([1,2,3,2,1,3,9,8,11,12,10,11,14,25,26,24,30,22,24,27])n_clusters = 3def Kmeans_1D(X, n_clusters, random_seed=442):  # Randomly choose random indexes as cluster centers rng ...

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