Open In App

NumPy ndarray nbytes() Method

The NumPy ndarray nbytes() function return the total bytes consumed by the elements of the array.

Notes

Syntax

Syntax: numpy.ndarray.nbytes(arr) 



Parameters 

  • arr : [array_like] Input array. 

Return 



  • [int] Total bytes consumed by the elements of the array.

Examples

Let’s see an example of how to use ndarray nbytes() method of NumPy library in Python.

Example 1




import numpy as np
arr = np.zeros((1, 2, 3), dtype = np.complex128)
  
bytes_consumed = arr.nbytes
  
print (bytes_consumed)

Output :

96

Example 2




# Python program explaining 
# numpy.ndarray.nbytes() function 
  
# importing numpy as geek 
import numpy as geek 
  
arr = geek.random.rand(10000, 50
  
gfg = arr.nbytes 
  
print (gfg) 

Output :

4000000
Article Tags :