w3resource logo
Python Exercises

Python NumPy: Check whether the numpy array is empty or not

Python NumPy: Array Object Exercise-95 with Solution

Write a Python program to check whether the numpy array is empty or not.

Sample Solution:-

Python Code:

import numpy as np
x = np.array([2, 3])
y = np.array([])
# size 2, array is not empty
print(x.size)
# size 0, array is empty
print(y.size)

Sample Output:

2                                                                      
0

Python Code Editor:

import numpy as np
x = np.array([2, 3])
y = np.array([])
# size 2, array is not empty
print(x.size)
# size 0, array is empty
print(y.size)

Improve this sample solution and post your code through Disqus