我有
from pylab import *
###FUNCTIONS##
def LOSS(y0,y1):
return sum(abs(y0-y1))
def genuchten(t,C,k):
return 1/(1+(C/t)**k)**(1-1/k)
###MAIN#######
if __name__ == '__main__':
t0 = linspace(0,10,100)
f0 = genuchten(t0,3,3)
x = linspace(1,10,10)
y = linspace(1,10,10)
X,Y = meshgrid(x,y)
Z = zeros(shape(X))
for i in range(len(x)):
for j in range(len(y)):
f = genuchten(t0,X[i][j],Y[i][j])
Z[i][j] = LOSS(f0,f)
contourf(X,Y,Z)
show()
这行得通,但我觉得必须有更直接的方法。似乎 MATLAB 有一个 ARRAYFUN 函数可以自动执行此操作?