This question already has an answer here:
这个问题已经有了答案:
- Comparing two numpy arrays for equality, element-wise 4 answers
- 比较两个数字数组的相等,元素-智慧4的答案。
Basically i am trying out boolean expressions with numpy arrays , for example something like this:
基本上,我正在尝试使用numpy数组的布尔表达式,例如:
import numpy as np
a = np.array([1,0,1])
b = np.array([0,1,1])
c = np.array([1,0,1])
if (a ==b) or (a==c):
d = [2,5,5]
else : d = [1,5,5]
print d
This returns an error
这将返回一个错误
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
ValueError:具有多个元素的数组的真值是不明确的。使用a.any()或所有()
What would be the correct way to code this?
编码这个的正确方法是什么?