Determine the size of the memory occupied by the array using NumPy.

In this python numpy program, we will determine the size of the memory occupied by the array using NumPy.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array using np.array().
  3. Get the size of the array using size.
  4. Get the memory occupied by the one element in the array in bytes using itemsize.
  5. Get the memory size of NumPy array in bytes using x.size * x.itemsize.
  6. Print the output.
				
					import numpy as np
x = np.array([10,34,86,26,56])

print("Size of the array: ",x.size)
print("Memory size of one array element in bytes: ", x.itemsize)
print("Memory size of numpy array in bytes:", x.size * x.itemsize)
				
			

Output :

				
					Size of the array:  5
Memory size of one array element in bytes:  4
Memory size of numpy array in bytes: 20
				
			

create an array with the values 10,34,86,26,56.

create an array of 3 ones using NumPy.

Leave a Comment