[英]numpy.dot(a, b) gives wrong result on multiplication of matrices with similar dimenstions
[英]numpy, summing matrices gives wrong result
當每個矩陣的最大值為255並且這些值位於相同的位置時,為什么將rgb通道矩陣加在一起不能得到765的最大結果? 但是,如果將所有矩陣除以255,則最大值為3。
import numpy as np
from PIL import Image
pic= Image.open(picture_dir)
r,g,b = pic.split()
g_ = np.asarray(g)
b_ = np.asarray(b)
r_ = np.asarray(r)
print((r_+g_+b_).max()) # gives result of 255, supposed to be 765
g_mat = np.asarray(g)/255
b_mat = np.asarray(b)/255
r_mat = np.asarray(r)/255
print((g_mat+b_mat+r_mat).max()) # gives result of 3.0
細分(例如:np.asarray(g)/ 255)是否會真正改變值以外的其他內容?
編輯:除以之前的dtype是uint8而除以float64之后的dtype
嘗試檢查g_,b_和r_的類型。
如果它們的類型為numpy.uint8,則應收到警告,結果應為253。
在第二種情況下,除法后將g_mat,b_mat和r_mat轉換為numpy.int64
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.