Quick answer: Use array.size == 0 to check whether a NumPy array contains no elements. Do not use if array for a multi-element array because NumPy cannot choose one truth value. An array containing zeros or NaN values is not empty.

The most reliable way to check whether a NumPy array is empty is to test whether it contains zero elements. In NumPy, that means checking array.size == 0.
The official NumPy documentation covers ndarray.size, numpy.size(), and numpy.empty().
An array is empty when its total element count is zero. Shape alone can be misleading because arrays may have several dimensions and still contain no elements.
len(array) only checks the first axis. That can give the wrong impression for arrays such as shape (1, 0), where the first axis has length one but the total size is zero.
Use array.size for validation, guards before calculations, and checks after filtering. It is direct, readable, and works across one-dimensional and multi-dimensional arrays.
np.size(array) gives the same total element count as array.size. The attribute form is usually shorter when you already have an ndarray.
Convert unknown input with np.asarray() first when a function may receive lists, tuples, or arrays.
Always decide whether empty data is valid for the workflow. Sometimes it should return early. Other times it should raise a clear error.
The examples below show the common checks and the shape cases that cause mistakes.
A practical rule is simple: if the question is “are there any elements?”, use size. If the question is “how many rows are there?”, inspect the first dimension or use len() deliberately.
That distinction keeps validation code honest. Empty arrays often appear after filtering, slicing, file loading, or reshaping, and each case may need a different response.
Check size
Use array.size == 0 for the basic check.
import numpy as np
array = np.array([])
is_empty = array.size == 0
print(is_empty)
This prints True because the array contains no elements.
This check works no matter how many dimensions the array has.
It is the clearest default for most NumPy code.
Use it before operations that require at least one value.
This includes reductions such as minimums, maximums, means, and other calculations that need data to produce a useful answer.
Avoid len For Total Emptiness
len() checks only the first axis.
import numpy as np
array = np.empty((1, 0))
print(len(array))
print(array.size)
print(array.size == 0)
This array has one row but zero total elements.
len(array) is 1, while array.size is 0.
That is why size is safer for checking emptiness.
Use len() only when the first-axis length is the specific question.
For table-like arrays, a row count can be useful, but it is not the same as a total element count. Keep those checks separate.

Use numpy.size
np.size() returns the total element count.
import numpy as np
array = np.zeros((0, 3))
count = np.size(array)
print(count)
print(count == 0)
The shape has two dimensions, but the total element count is zero.
This is a common shape for a filtered table with no rows.
np.size(array) and array.size both handle it correctly.
Choose the style that fits the surrounding code.
The attribute form is common in object-oriented NumPy code. The function form can be handy when code already uses other NumPy functions in the same expression.
Check After Filtering
Empty arrays often appear after a filter removes every value.
import numpy as np
values = np.array([2, 4, 6])
filtered = values[values > 10]
if filtered.size == 0:
print("no matches")
else:
print(filtered.mean())
This avoids calling mean() on an empty result.
Guard clauses like this make data-processing code easier to review.
They also let you choose a clear fallback when no values match.
For some workflows, returning an empty array is fine. For others, a message or exception is better.
Choose the behavior close to the filtering step. That makes it clear whether no matches are expected, rare, or an actual data problem.

Write A Helper Function
A helper can normalize input before checking it.
import numpy as np
def is_empty_array(data):
array = np.asarray(data)
return array.size == 0
print(is_empty_array([]))
print(is_empty_array([[1, 2]]))
This accepts Python lists as well as NumPy arrays.
The helper converts the input to an array, then checks total size.
Use this approach when the same validation appears in several functions.
Keep the helper small so its behavior stays obvious.
If the helper will be used in public code, document that it checks total element count, not first-axis length.
Compare Empty And Uninitialized Arrays
np.empty() creates an array without filling values, but it is not necessarily empty in the size sense.
import numpy as np
no_elements = np.empty((0, 3))
unfilled = np.empty((2, 3))
print(no_elements.size == 0)
print(unfilled.size == 0)
The first array has zero elements.
The second array has six elements, even though the values are uninitialized.
Do not confuse uninitialized storage with an empty array.
The name empty in np.empty() means values are not initialized, not that the array necessarily has zero elements. Shape decides the size.
In short, use array.size == 0 to check if a NumPy array is empty, use np.asarray() for uncertain input, and avoid relying on len() when total element count matters.
Use size For Total Emptiness
size counts elements across every dimension and returns zero for an array with no elements. It is the most direct test when the operation should skip any zero-size array.

Use shape For Dimension Rules
shape describes each dimension. If the operation requires a non-empty first axis, inspect shape[0]; if it requires any dimension to be nonzero, express that policy separately from total size.
Separate Empty From Falsey
A NumPy array can contain zero, False, empty strings, or NaN values and still have elements. Use isnan for missing floating values and comparisons for numeric content rather than treating those cases as empty.

Avoid Ambiguous Truth Tests
Python’s if array is rejected for arrays with more than one element because there is no single truth value. Use size, any, or all according to the actual requirement.
Preserve The Shape Contract
Check emptiness before indexing, reducing, concatenating, or broadcasting. Document whether an empty result is valid and whether a one-dimensional or multidimensional empty shape is expected from upstream code.
NumPy’s ndarray.size and shape references define the relevant properties. Related references include axis behavior, NaN-aware reductions, and array operations.
For related array policies, compare axis behavior, NaN-aware reductions, and array operations when checking content.
Frequently Asked Questions
How do I check if a NumPy array is empty?
Use array.size == 0, which checks the total number of elements across all dimensions.
Why can I not use if array?
A multi-element NumPy array has no single truth value, so Python raises an ambiguous truth-value error.
Is an array of NaN values empty?
No. NaN values are elements; use isnan when the requirement is missing-value detection rather than emptiness.
How do I check an empty dimension?
Inspect shape or size depending on whether any zero-length dimension or the total element count defines empty for the operation.