The NumPy array object
NumPy has a multidimensional array object called ndarray
. It consists of two parts, which are as follows:
The actual data
Some metadata describing the data
The bulk of array procedures leaves the raw information unaffected; the sole facet that varies is the metadata.
We have already discovered in the preceding chapter how to produce an array by applying the arange()
function. Actually, we made a one-dimensional array that held a set of numbers. The ndarray
can have more than a single dimension.
The advantages of NumPy arrays
The NumPy array is, in general, homogeneous (there is a particular record array type that is heterogeneous)—the items in the array have to be of the same type. The advantage is that if we know that the items in an array are of the same type, it is easy to ascertain the storage size needed for the array. NumPy arrays can execute vectorized operations, processing a complete array, in contrast to Python lists, where you usually have to loop through the...