How much memory is used by a numpy ndarray? How much memory is used by a numpy ndarray? numpy numpy

How much memory is used by a numpy ndarray?


The array is simply stored in one consecutive block in memory. Assuming by "float" you mean standard double precision floating point numbers, then the array will need 8 bytes per element.

In general, you can simply query the nbytes attribute for the total memory requirement of an array, and itemsize for the size of a single element in bytes:

>>> a = numpy.arange(1000.0)>>> a.nbytes8000>>> a.itemsize8

In addtion to the actual array data, there will also be a small data structure containing the meta-information on the array. Especially for large arrays, the size of this data structure is negligible.


I gauss, easily, we can compute by print(a.size // 1024 // 1024, a.dtype)it is similar to how much MB is uesd, however with the param dtype, float=8B, int8=1B ...