Summary

This chapter informed us about a great number of common NumPy functions. We read a file with loadtxt and wrote to a file with savetxt. We made an identity matrix with the eye function. We read a CSV file containing stock quotes with the loadtxt function. The NumPy average and mean functions allow one to calculate the weighted average and arithmetic mean of a data set.

A few common statistics functions were also mentioned – first, the min and max functions that we used to determine the range of the stock prices; second, the median function that gives the median of a data set; and finally, the std and var functions that return the standard deviation and variance of a set of numbers.

We calculated the simple stock returns with the diff function that returns back the differences between sequential elements. The log function computes the natural logarithms of array elements.

By default, loadtxt tries to convert all data into floats. The loadtxt function has a special parameter for this purpose. The parameter is called converters and is a dictionary that links columns with the so-called converter functions.

We defined a function and passed it as an argument to the apply_along_axis function. We implemented an algorithm with the requirement to find the maximum value across arrays.

We learned that the ones function can create an array with ones and the convolve function calculates the convolution of a data set with the specified weights.

We computed exponentially decreasing weights with the exp and linspace functions. linspace gave us an array with evenly spaced elements, and then we calculated the exponential for these numbers. We called the ndarray sum method in order to normalize the weights.

We got acquainted with the NumPy fill function. This function fills an array with a scalar value, the only parameter of the fill function.

After this tour through the common NumPy functions, we will continue covering convenience NumPy functions such as polyfit, sign, and piecewise in the next chapter.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.36.249