我在python中工作。我想获得归一化的矩阵M,但我不知道如何从循环中存储数据。
IMGa = np.asarray(img)
n = np.size(IMGa, 1)
m = np.size(IMGa, 0)
MEAN = (1/(n*m))*np.sum(IMGa)
VAR = (1/(n*m))*(np.sum((IMGa - MEAN)**2))
M0 = 100
V0 = 100
i = IMGa[0, :]
j = IMGa[:, 0]
for i in range(np.size(IMGa, 1)):
for j in range(np.size(IMGa, 0)):
if i == n:
j += 1
elif j == m:
break
if IMGa[i, j] > MEAN:
M = M0 + (math.sqrt((V0*((IMGa[i, j] - MEAN)**2))/VAR))
elif IMGa[i, j] < MEAN:
M = M0 - (math.sqrt((V0*((IMGa[i, j] - MEAN)**2))/VAR))
print(M)
回答您的特定问题。创建具有相同形状的数组以将值放入。