ValueError: operands could not be broadcast together with shapes

Peter Otten __peter__ at web.de
Sun Aug 6 11:19:08 EDT 2017


Ho Yeung Lee wrote:

> def mse(imageA, imageB):
>     err = np.sum((imageA.astype("float") - imageB.astype("float")) ** 2)
>     err /= float(imageA.shape[0] * imageA.shape[1])
>     return err
> 
> original = cv2.imread("C:\\Users\\hello\\Documents\\words\\" + xx)
> later = cv2.imread("C:\\Users\\hello\\Documents\\words\\"+ yy)
> mserr = mse(original, later)
> 
> Traceback (most recent call last):
>   File "words29.py", line 135, in <module>
>     mserr = mse(original, later)
>   File "words29.py", line 27, in mse
>     err = np.sum((imageA.astype("float") - imageB.astype("float")) ** 2)
> ValueError: operands could not be broadcast together with shapes (7,29,3)
> (7,37,3)

These are probably images represented as numpy arrays. To calculate the 
pixelwise difference both images have to have the same size whereas one of 
your samples seems to be 7x29xRGB, and the other 7x37xRGB.





More information about the Python-list mailing list