Home > Blockchain >  numpy.nbytes unclear meaning
numpy.nbytes unclear meaning

Time:04-14

From numpy documentation:

numpy.ndarray.nbytes¶ attribute

ndarray.nbytes Total bytes consumed by the elements of the array.

Notes

Does not include memory consumed by non-element attributes of the array object.

The following code:

x = np.zeros((3,5,2), dtype=np.uint64)
x[0].nbytes

Outputs:

80

Why?

Again from numpy documentation:

numpy.uint64: 64-bit unsigned integer

CodePudding user response:

In python (an in general), one int64 consumes 8 bytes of memory.

Slicing x[0] you get 10 elements:

x[0]
array([[0, 0],
       [0, 0],
       [0, 0],
       [0, 0],
       [0, 0]], dtype=uint64)

x[0].size
10

10*8 is 80, all is logical, no?

  • Related