我想用no计算一个复合函数f(x,g(x))。不幸的是,当我试图编写一个函数组合时,Python抱怨一个类型错误。例如,考虑以下简单脚本:
import theano
import theano.tensor as T
x = T.dscalar('x')
def g():
y1 = T.sqr(x)
return theano.function([x], y1)
def composition():
input = g()
yComp = x * input
return theano.function([x], yComp)
def f():
y1 = T.sqr(x)
yMult = x * y1
return theano.function([x], yMult)
写入 funComp = composition()
时,Python返回一个TypeError:
但是,我可以编译和计算函数 fun = f()
。有没有办法成功地建立一个功能组合?我很感激你的帮助!在
在这种情况下,实际上并不需要多个函数。这个很好用。在
相关问题 更多 >
编程相关推荐