1.

How do we check for an empty array (or zero elements array)?

Answer»

We can check for the emptiness of a NumPy array by making use of the size attribute.
Let us consider the below example. We have NumPy array arr filled with zeros. If the size element returns zero, that means the array is empty or it only consists of zeros.

import numpy as np
arr = np.zeros((1,0)) #returns empty array
print(arr.size) #returns 0

This return 0




Discussion

No Comment Found