Python Practice › NumPy Programs › Program 79
Is an array empty?
Write a NumPy program to check whether an array is empty.
Input
[4, 8, 0], []
Output
[4 8 0] Array is not empty [] Array is empty
Approach
- Check
a.size == 0.
Solution
import numpy as npfor a in [np.array([4, 8, 0]), np.array([])]: print(a, "Array is empty" if a.size == 0 else "Array is not empty")Output
[4 8 0] Array is not empty [] Array is empty
Learn the concept
New to this topic? Read the lesson, then come back.