What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Use arr.size == 0 to check whether a NumPy array contains zero elements. Unlike len(arr), arr.size counts elements across every dimension.
Check whether the array contains any elements
ndarray.size is the total number of elements in a NumPy array. Test it against zero:
if arr.size == 0:
print("array has no elements")
This checks element count, not the values stored in the array. An array filled with numeric zeros is not empty if it has elements.
What is the difference between size and len?
arr.size counts every element. For an ndarray, len(arr) gives the length of the first dimension. In one dimension these counts match; in multiple dimensions they can differ.
#1 Best Overall
import numpy as np
one_d = np.array([])
print(one_d.size == 0) # True
print(len(one_d) == 0) # True
zero_columns = np.empty((3, 0))
print(zero_columns.size == 0) # True
print(len(zero_columns) == 0) # False: first dimension has length 3
The second array has shape (3, 0): its first dimension has length three, but its second dimension has length zero, so it contains no elements. Use arr.size == 0 when you mean that the entire array has zero elements.
How do shapes and scalar arrays affect the check?
Any shape with a zero-length dimension has zero total elements. For example, (0,), (0, 4), and (3, 0) all satisfy arr.size == 0. By contrast, a zero-dimensional array is scalar-shaped and can contain one element. The number of dimensions, shape, and total element count describe different properties; size checks the last one.
Rank #2
When should you use len or another property?
- Use
arr.size == 0to test for zero total elements, including in multidimensional arrays. - Use
len(arr)when you specifically need the length of the first dimension. - Use
arr.nbyteswhen you need the array’s memory consumption in bytes;arr.sizeis a count of elements, not bytes.
The size attribute applies to NumPy arrays. If your input may instead be a Python list or another object, decide whether to convert it to an array before using this check.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Repair Windows errors before they cause bigger problems3Fix the driver behind crashes, sound loss and screen glitches




