[~np isnan( )array( ]np mean( [~np isnan( )] comparing runtime behaviors let us compare the runtime behavior of numpy with normal python lists in the following codewe will calculate the sum of all squared numbers of to and see how much time the calculation will take we do it times and report the total time so that our measurement is accurate enough import timeit normal_py_sec timeit timeit('sum( * for in xrange( ))'number= naive_np_sec timeit timeit('sum(na*na)'setup="import numpy as npna=np arange( )"number= good_np_sec timeit timeit('na dot(na)'setup="import numpy as npna=np arange( )"number= print("normal python% sec"%normal_py_secprint("naive numpy% sec"%naive_np_secprint("good numpy% sec"%good_np_secnormal python sec naive numpy sec good numpy sec we make two interesting observations firstjust using numpy as data storage (naive numpytakes times longerwhich is surprising since we believe it must be much faster as it is written as extension one reason for this is that the access of individual elements from python itself is rather costly only when we are able to apply algorithms inside the optimized extension code do we get speed improvementsand tremendous ones at thatusing the dot(function of numpywe are more than times faster in summaryin every algorithm we are about to implementwe should always look at how we can move loops over individual elements from python to some of the highly optimized numpy or scipy extension functions