The NumPy array object
NumPy provides a multidimensional array object called ndarray
. NumPy arrays are typed arrays of a fixed size. Python lists are heterogeneous and thus elements of a list may contain any object type, while NumPy arrays are homogenous and can contain objects of only one type. An ndarray
consists of two parts, which are as follows:
The actual data that is stored in a contiguous block of memory
The metadata describing the actual data
Since the actual data is stored in a contiguous block of memory, hence loading of the large dataset as ndarray
, it is affected by the availability of a large enough contiguous block of memory. Most of the array methods and functions in NumPy leave the actual data unaffected and only modify 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.