the part of my code that has a problem is:
history = np.array([[0, 0, 1, 1],[1, 0, 0, 1]])
opponentsActions = history[1]
if opponentsActions == [0, 0, 0, 0]:
print("nice")
and the error I get is: ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
When you execute your check, you receive array representing comparision
>>> opponentsActions == [0, 0, 0, 0]
array([False, True, True, False])
You are prompted to use any() or all() and that's quite a helpful hint. All(something) means all elements of something you want to check has to be true. So in your case:
>>> np.all(opponentsActions == [0, 0, 0, 0])
False
You are comparing a numpy array with Python list, that won't work, a quick workaround can be converting the numpy array to python list using tolist() where you are comparing, it will work that way, have a look:
history = np.array([[0, 0, 1, 1],[0, 0, 0, 0]])
opponentsActions = history[1]
print(opponentsActions)
if opponentsActions.tolist() == [0, 0, 0, 0]:
print("nice")
Or you can use np.all as suggested by SebaLenny.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.