Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

numpy.nbytes unclear meaning

From numpy documentation:

numpy.ndarray.nbytes¶ attribute

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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?

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading