Find length of one array element in bytes and total bytes consumed by the elements in Numpy

In NumPy we can find the length of one array element in a byte with the help of itemsize . It will return the length of the array in integer. And in the numpy for calculating total bytes consumed by the elements with the help of nbytes.

Syntax: array.itemsize

Return :It will return length(int) of the array in bytes.

Syntax: array.nbytes



Return :It will return total bytes consumed by the elements.

Example 1:

Python

filter_none

edit
close

play_arrow

link
brightness_4
code

import numpy as np
  
  
arry = np.array([1,3,5], dtype=np.float64)
  
# Size of the array 
print(arry.size)
  
# Length of one array element in bytes,
print( arry.itemsize)
  
# Total bytes consumed by the elements 
# of the array
print(arry.nbytes)

chevron_right


Output:

3
8
24

Example 2:

Python

filter_none

edit
close

play_arrow

link
brightness_4
code

import numpy as np
  
  
arry = np.array([20, 34, 56, 78, 1, 9], dtype=np.float64)
  
# Size of the array
print(arry.size)
  
# Length of one array element in bytes,
print(arry.itemsize)
  
# Total bytes consumed by the elements
# of the array
print(arry.nbytes)

chevron_right


Output:

6
8
48

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.