Skip to content
Advertisement

How can I check whether a numpy array is empty or not?

How can I check whether a numpy array is empty or not?

I used the following code, but this fails if the array contains a zero.

JavaScript

Is this the solution?

JavaScript

Advertisement

Answer

You can always take a look at the .size attribute. It is defined as an integer, and is zero (0) when there are no elements in the array:

JavaScript
Advertisement