我已經在python中創建了一個能量函數,我正將它應用於一個png圖像。但是,輸入參數時,我沒有收到返回的能量值。任何人都可以看到這是爲什麼?謝謝!能量函數不返回值
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
img=mpimg.imread('Image.png')
#plt.imshow(img)
#plt.show()
im=np.array(img
def E_generator(beta, eta, h):
"""Generate energy function E and localized version of E.
E = h * \sum{x_i} - beta * \sum{x_i x_j} - eta * \sum{x_i y_i}
"""
def E(x, y):
"""Calculate energy for matrices x, y.
"""
# sum of products of neighboring paris {xi, yi}
xxm = np.zeros_like(x)
xxm[:-1, :] = x[1:, :] # down
xxm[1:, :] += x[:-1, :] # up
xxm[:, :-1] += x[:, 1:] # right
xxm[:, 1:] += x[:, :-1] # left
xx = np.sum(xxm * x)
xy = np.sum(x * y)
xsum = np.sum(x)
return h * xsum - beta * xx - eta * xy
return E
y = np.array(img)
x = np.array(y)
E_generator(0,1,1)
與然後輸出返回: 「.E>」
'E_generator'返回'E'函數。誰叫'E'? – Pynchia
它出來與「E ---功能---等」只是堆棧wouldnt讓我打印整個聲明 – user4476006