centers is a list, [ ], of numpy arrays. shortest_dist[1] is an numpy array. However, when I do:
centers.index(shortest_dist[1])
It tells me
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
This is weird, so I tried the following things:
See the following demo. I cannot make sense of what's happening.
>>>
>>>
>>>
>>> a = np.asarray([1,2,3,4,5])
>>> b = np.asarray([2,3,4,5,6])
>>> c = []
>>> c.append(a)
>>> c.append(b)
>>> c.index(a)
0
>>> c.index(c[0])
0
>>> c.index(c[1])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
>>> c.index(b)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
>>> len(c)
2
>>> c[1]
array([2, 3, 4, 5, 6])
>>> b
array([2, 3, 4, 5, 6])
>>> c.index(b)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
>>>
So it's okay to query the index of a, but not b, although both are numpy arrays? Does this have to do when my error, which is mentioned at the beginning of the question?