当我运行if field[x,y,z] != [-1,-1,-1]:
时显示此错误:
Traceback (most recent call last):
File "C:\Users\dinos\Desktop\CODE\Render\Camera.py", line 63, in controll
print(self.snap())
File "C:\Users\dinos\Desktop\CODE\Render\Camera.py", line 59, in snap
return "".join(self.breakUpArray(self.pBetweenPlane(),self.ep["ab"]))+"\n"+self.getInfo()
File "C:\Users\dinos\Desktop\CODE\Render\Camera.py", line 42, in pBetweenPlane
if self.field.field[p2[0],p2[1],p2[2]] != self.field.background:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
“field”是一个用 np.full([100, 100, 100, 3], -1)
创建的 4d-np 数组。我知道错误消息确实给出了提示,但我如何检查 if field[x,y,z] is not [-1,-1,-1]
?
最佳答案
np.array([-1, -1, -1]) == [-1, -1, -1]
计算结果为 [True, True, True]
as numpy 按索引比较它们
你可能想要if not all(field[x,y,z] == [-1,-1,-1])
关于python - Numpy bool 逻辑(检查元素是否不是什么),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64921164/