Program to check whether the NumPy array is empty

In this python numpy program, we will check whether the NumPy array is empty.

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 (i.e. total number of elements) using size.
  4. Determine whether the given array is empty or not using an if-else statement.
  5. If the size of the array is 0 then the array is empty else the array is not empty.
  6. Print the respective output.
				
					import numpy as np
x = np.array([4,8,0])

if x.size == 0:
    print("Array is empty")
else:
    print("Array is not empty")
				
			

Output :

				
					Array is not empty
				
			

count the frequency of unique values.

calculate the product of an array.

Leave a Comment