Google News
logo
NumPy - Interview Questions
How do you check for an empty (zero Element) array?
If the variable is an array, you can check for an empty array by using the size attribute. However, it is possible that the variable is a list or a sequence type, in that case, you can use len().
 
The preferable way to check for a zero element is the size attribute. This is because : 
a = NumPy.zeros((1,0))
a.size
0
 
whereas

len(a)
1​
Advertisement