OTHER USEFUL NUMPY METHODS
In addition to the NumPy methods that you saw in the code samples prior to this section, the following NumPy methods are also useful.
- The method
np.zeros()initializes an array with 0 values. - The method
np.ones()initializes an array with 1 value. - The method
np.empty()initializes an array with 0 values. - The method
np.arange()provides a range of numbers. - The method
np.shape()displays the shape of an object. - The method
np.reshape()<= very useful! - The method
np.linspace()<= useful in regression - The method
np.mean()computes the mean of a set of numbers. - The method
np.std()computes the standard deviation of a set of numbers.
Although the np.zeros() and np.empty() both initialize a 2D array with 0, np.zeros() requires less execution time. You could also use np.full(size, 0), but this method is the slowest of all three methods.
The reshape() method and the linspace() method are very useful for changing the dimensions of an array and generating a list...