NumPy internals
As you have seen in previous chapters, NumPy arrays make numerical computations efficient and its API is intuitive and easy to use. NumPy array are also core to other scientific libraries as many of them are built on top of NumPy arrays.
In order to write better and more efficient code, you need to understand the internals of data handling. A NumPy array and its metadata live in a data buffer, which is a dedicated block of memory with certain data items.
How does NumPy manage memory?
Once you initialize a NumPy array, its metadata and data are stored at allocated memory locations in Random Access Memory (RAM).
import numpy as np array_x = np.array([100.12, 120.23, 130.91])
First, Python is a dynamically typed languages; there is no need for the explicit declaration of variables types such as int
or double
. Variable types are inferred and you'd expect that in this case the data type of array_x
is np.float64
:
print(array_x.dtype) float64
The advantage of using the numpy
library rather...