import numpy as np
mainList = []
numpyArray0 = np.array([1,2,3])
numpyArray1 = np.array([4,5,6])
mainList.append(numpyArray0)
mainList.append(numpyArray1)
print("numpyArray0 in mainList:")
try:
print(numpyArray0 in mainList)
except ValueError:
print("ValueError")
print("numpyArray1 in mainList:")
try:
print(numpyArray1 in mainList)
except ValueError:
print("ValueError")
print("mainList in numpyArray0:")
try:
print(mainList in numpyArray0)
except ValueError:
print("ValueError")
print("mainList in numpyArray1:")
try:
print(mainList in numpyArray1)
except ValueError:
print("ValueError")
print(numpyArray1 in mainList)
So I have the above code basically it creates 2 numpy arrays inside a normal python list (mainList) and then it checks to see if those 2 arrays are inside the list. The code should output:
numpyArray0 in mainList:
True
numpyArray1 in mainList:
**True**
mainList in numpyArray0:
True
mainList in numpyArray1:
True
**True**
But instead of outputing the above it outputs the following:
numpyArray0 in mainList:
True
numpyArray1 in mainList:
ValueError
mainList in numpyArray0:
True
mainList in numpyArray1:
True
Traceback (most recent call last):
File "/home/user/Documents/pythonCode/temp.py", line 31, in <module>
print(numpyArray1 in mainList)
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Am I doing anything incorrectly? Note that I tried updating python, numpy, and my os (debian) before running the code.
print("numpyArray0:")all the way down and keepnumpyArray0 in mainListandnumpyArray1 in mainList- to make the question clear and simple.intest is not reliable unless you are clearly comparing object ids (e.g. an object class without the compare method), or the compare method itself is reliable (for your purposes).