let us test the code interactively in python shell to compute dt the file with the code above has the name integration_methods_vec py and is valid module from which we can import the vectorized functionfrom integration_methods_vec import midpoint from numpy import exp lambda * ** *exp( ** midpoint( note the necessity to use exp from numpyour function will be called with as an arrayand the exp function must be capable of working with an array the vectorized code performs all loops very efficiently in compiled coderesulting in much faster execution moreovermany readers of the code will also say that the algorithm looks clearer than in the loop-based implementation vectorizing the trapezoidal rule we can use the same approach to vectorize the trapezoid function howeverthe trapezoidal rule performs sum where the end points have different weight if we do sum( ( ))we get the end points (aand (bwith weight unity instead of one half remedy is to subtract the error from sum( ( ))sum( ( ) * ( * (bthe vectorized version of the trapezoidal method then becomes def trapezoidal(fabn) float( - )/ linspace(abn+ sum( ( ) * ( * (breturn * measuring computational speed now that we have created fastervectorized versions of functions in the previous sectionit is interesting to measure how much faster they are the purpose of the present section is therefore to explain how we can record the cpu time consumed by function so we can answer this question there are many techniques for measuring the cpu time in pythonand here we shall just explain the simplest and most convenient onethe %timeit command in ipython the following interactive session should illustrate competition where the vectorized versions of the functions are supposed to winin [ ]from integration_methods_vec import midpoint as midpoint_vec in [ ]from midpoint import midpoint in [ ]from numpy import exp in [ ] lambda * ** *exp( **