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 nparray_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 than Python is that numpy supports many different numerical data types such as bool_, int_, intc, intp, int8, int16, int32, int64, uint8, uint16, uint32, uint64, float_, float16, float32, float64, complex_, complex64 ...

Get Mastering Numerical Computing with NumPy now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.