I believe this is what's going on:

When you use a comparison operator on a NumPy array, it returns an array of booleans with the same shape as the input array. Each value is the result of bool(x[i] == 4)

if you have a list, you get

>>> bool([4, 4, 4] == 4)
False

with a numpy array, you get:

>>> bool(np.array([4, 4, 4]) == 4)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-17-65795746028a> in <module>()
----> 1 bool(np.array([4, 4, 4]) == 4)

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

I would have thought that numpy would propagate this error through, but it doesn't. For some reason it decides to evaluate the entire expression as False. It might be worth bringing this up on the numpy issue tracker.

As for solving your problem... is there any way you can use lists rather than arrays within your object array? I can't think of another way to get around it.

Edit: I submitted an issue at https://github.com/numpy/numpy/issues/5016

Edit2: According to numpy developers, the current version of numpy raises a warning in this situation, and a future version will raise a ValueError when the elementwise comparison fails.

Answer from jakevdp on Stack Overflow
🌐
NumPy
numpy.org › doc › stable › reference › arrays.dtypes.html
Data type objects (dtype) — NumPy v2.5 Manual
Whenever a data-type is required in a NumPy function or method, either a dtype object or something that can be converted to one can be supplied.
🌐
W3Schools
w3schools.com › python › numpy › numpy_data_types.asp
NumPy Data Types
We use the array() function to create arrays, this function can take an optional argument: dtype that allows us to define the expected data type of the array elements: ... import numpy as np arr = np.array([1, 2, 3, 4], dtype='S') print(arr) ...
🌐
NumPy
numpy.org › doc › stable › user › basics.types.html
Data types — NumPy v2.5 Manual
NumPy numerical types are instances of numpy.dtype (data-type) objects, each having unique characteristics. Once you have imported NumPy using import numpy as np you can create arrays with a specified dtype using the scalar types in the numpy top-level API, e.g.
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.dtype.html
numpy.dtype — NumPy v2.5 Manual
Returns dtype for the base element of the subarrays, regardless of their dimension or shape.
🌐
Python Course
python-course.eu › numerical-programming › numpy-data-objects-dtype.php
3. Numpy Data Objects, dtype | Numerical Programming
Before we work with a complex data structure like the one shown above, let’s first introduce dtype using a very simple example. We define a data type based on int16 and refer to it as i16. (Admittedly, this isn’t a very descriptive name, but we’ll use it just for this example.) The elements of a list named lst are then converted to the i16 type to create a two-dimensional array called A. import numpy as np i16 = np.dtype(np.int16) print(i16) lst = [ [3.4, 8.7, 9.9], [1.1, -7.8, -0.7], [4.1, 12.3, 4.8] ] A = np.array(lst, dtype=i16) print(A)
Top answer
1 of 2
3

I believe this is what's going on:

When you use a comparison operator on a NumPy array, it returns an array of booleans with the same shape as the input array. Each value is the result of bool(x[i] == 4)

if you have a list, you get

>>> bool([4, 4, 4] == 4)
False

with a numpy array, you get:

>>> bool(np.array([4, 4, 4]) == 4)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-17-65795746028a> in <module>()
----> 1 bool(np.array([4, 4, 4]) == 4)

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

I would have thought that numpy would propagate this error through, but it doesn't. For some reason it decides to evaluate the entire expression as False. It might be worth bringing this up on the numpy issue tracker.

As for solving your problem... is there any way you can use lists rather than arrays within your object array? I can't think of another way to get around it.

Edit: I submitted an issue at https://github.com/numpy/numpy/issues/5016

Edit2: According to numpy developers, the current version of numpy raises a warning in this situation, and a future version will raise a ValueError when the elementwise comparison fails.

2 of 2
2

Somehow the nested np.array disturb the element-wise condition == 4. Nesting normal lists works just fine:

import numpy as np
foo = np.array([[0, 2, 3], [0, 2, 3], [4, 4], 4], dtype=object)
np.where(foo == 4)

But I'm not sure why this makes the difference.

🌐
NumPy
numpy.org › doc › 2.1 › reference › arrays.dtypes.html
Data type objects (dtype) — NumPy v2.1 Manual
NumPy allows a modification on the format in that any string that can uniquely identify the type can be used to specify the data-type in a field. The generated data-type fields are named 'f0', 'f1', …, 'f<N-1>' where N (>1) is the number of comma-separated basic formats in the string.
🌐
NumPy
numpy.org › devdocs › user › basics.types.html
Data types — NumPy v2.6.dev0 Manual
NumPy numerical types are instances of numpy.dtype (data-type) objects, each having unique characteristics. Once you have imported NumPy using import numpy as np you can create arrays with a specified dtype using the scalar types in the numpy top-level API, e.g.
🌐
NumPy
numpy.org › doc › 2.2 › reference › generated › numpy.ndarray.dtype.html
numpy.ndarray.dtype — NumPy v2.2 Manual
Setting will replace the dtype without modifying the memory (see also ndarray.view and ndarray.astype).
Find elsewhere
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.ndarray.dtype.html
numpy.ndarray.dtype — NumPy v2.4 Manual
January 31, 2021 - Setting will replace the dtype without modifying the memory (see also ndarray.view and ndarray.astype). ... Cast the values contained in the array to a new data-type. ... Create a view of the same data but a different data-type. ... Try it in your browser! >>> import numpy as np >>> x = np.arange(4).reshape((2, 2)) >>> x array([[0, 1], [2, 3]]) >>> x.dtype dtype('int64') # may vary (OS, bitness) >>> isinstance(x.dtype, np.dtype) True
🌐
GeeksforGeeks
geeksforgeeks.org › data-type-object-dtype-numpy-python
Data type Object (dtype) in NumPy Python - GeeksforGeeks
August 11, 2021 - # Python Program to create a data type object # containing a 32 bit big-endian integer import numpy as np # i4 represents integer of size 4 byte # > represents big-endian byte ordering and < represents little-endian encoding. # dt is a dtype object dt = np.dtype('>i4') print("Byte order is:",dt.byteorder) print("Size is:",dt.itemsize) print("Data type is:",dt.name)
🌐
NumPy
numpy.org › doc › 2.3 › reference › arrays.dtypes.html
Data type objects (dtype) — NumPy v2.3 Manual
A data type object (an instance of numpy.dtype class) describes how the bytes in the fixed-size block of memory corresponding to an array item should be interpreted.
🌐
NumPy
numpy.org › doc › 2.2 › reference › arrays.dtypes.html
Data type objects (dtype) — NumPy v2.2 Manual
NumPy allows a modification on the format in that any string that can uniquely identify the type can be used to specify the data-type in a field. The generated data-type fields are named 'f0', 'f1', …, 'f<N-1>' where N (>1) is the number of comma-separated basic formats in the string.
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.dtype.html
numpy.dtype — NumPy v2.1 Manual
Boolean indicating whether this dtype contains any reference-counted objects in any fields or sub-dtypes.
🌐
Numpy
numpy.net › doc › stable › reference › arrays.dtypes.html
Data type objects (dtype) — NumPy v1.26 Manual
NumPy allows a modification on the format in that any string that can uniquely identify the type can be used to specify the data-type in a field. The generated data-type fields are named 'f0', 'f1', …, 'f<N-1>' where N (>1) is the number of comma-separated basic formats in the string.
🌐
NumPy
numpy.org › doc › 2.0 › reference › arrays.dtypes.html
Data type objects (dtype) — NumPy v2.0 Manual
NumPy allows a modification on the format in that any string that can uniquely identify the type can be used to specify the data-type in a field. The generated data-type fields are named 'f0', 'f1', …, 'f<N-1>' where N (>1) is the number of comma-separated basic formats in the string.
🌐
GeeksforGeeks
geeksforgeeks.org › python › check-data-type-in-numpy
Check data type in NumPy - GeeksforGeeks
July 23, 2025 - Creating the array with a defined datatype. Creating numpy array by using an array function array(). This function takes argument dtype that allows us to define the expected data type of the array elements:
🌐
Note.nkmk.me
note.nkmk.me › home › python › numpy
NumPy: astype() to change dtype of an array | note.nkmk.me
February 4, 2024 - NumPy arrays (ndarray) cannot be specified. You need to specify either the data type of the array or provide a specific value instead. a = np.array([1, 2, 3], dtype=np.int8) print(type(a)) # <class 'numpy.ndarray'> # print(np.iinfo(a)) # ValueError: Invalid integer data type 'O'. print(np.iinfo(a.dtype)) # Machine parameters for int8 # --------------------------------------------------------------- # min = -128 # max = 127 # --------------------------------------------------------------- # print(np.iinfo(a[0])) # Machine parameters for int8 # --------------------------------------------------------------- # min = -128 # max = 127 # --------------------------------------------------------------- #
🌐
NumPy
numpy.org › devdocs › reference › generated › numpy.dtype.html
numpy.dtype — NumPy v2.6.dev0 Manual
Returns dtype for the base element of the subarrays, regardless of their dimension or shape.
🌐
GeeksforGeeks
geeksforgeeks.org › python › numpy-data-type-objects
NumPy - Data type Objects(dtype) - GeeksforGeeks
July 23, 2025 - import numpy as np # Structured dtype with multiple fields person_dtype = np.dtype([('name', 'S10'), ('age', 'i4'), ('height', 'f4')]) people = np.array([('John', 28, 5.9), ('Emma', 32, 5.5)], dtype=person_dtype) print(people['name']) # Access 'name' field