Let’s learn how to check if array is empty in Numpy Python library. We will use clever trick.
Checking if empty
To check if an array is empty it is enough to check the size of the array.
Let’s see example function which will print out if array is empty.
import numpy as np my_array = np.array([]) def if_empty_array(array): if array.size == 0: print(f"Array is empty") else: print(f"Array is NOT empty") if_empty_array(my_array)
An example array is empty so Python will print such information.