我的代码是:
import cv2
from PIL import Image
import numpy as np
img=cv2.imread("IMG040.jpg")
img2=cv2.imread("IMG040.jpg")
p1 = np.array(img)
p2 = np.array(img2)
img3=img-img2
p3 = np.array(img3)
if p3==0 :
print "the same"
else:
print"not the same"
but I have this problem
File "part2.py", line 10, in <module>
if p3==0 :
错误消息:
^{pr2}$
表达式
创建布尔numpy数组。Python
if
语句不知道如何将整个数组解释为true或false。这就是错误消息的意思。您可能想知道是否所有元素都为零,这就是为什么错误消息建议您使用all()
。在最后,你会这样做的
^{pr2}$但是,比较numpy数组和
allclose
方法更好,后者可以解释数值错误。所以试着换掉这个与
你需要这样做if语句:
相关问题 更多 >
编程相关推荐