ano TypeError:function()至少接受1个参数(给定1个)

2024-05-15 05:12:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我的一个Theano函数不接受任何输入,只使用共享变量来计算输出。但是这个函数抛出一个TypeError: function() takes at least 1 argument (1 given)。在

这里有一个最小的例子:

import theano as th
import theano.tensor as T
import numpy as np

x, y = T.dscalars('x', 'y')
z = th.shared(np.zeros(2))

f1 = th.function(inputs=[x], updates=[(z, z+x)]) 
f2 = th.function(outputs=z)
f1(3)
print f2()


Traceback (most recent call last):
  File "/home/me/temp/theano.test.py", line 9, in <module>
    f2 = th.function(updates=[(z, z*z)])
TypeError: function() takes at least 1 argument (1 given)

Tags: 函数importasnpfunctiontheanoargumentgiven
1条回答
网友
1楼 · 发布于 2024-05-15 05:12:52

发件人:https://stackoverflow.com/a/16782594/380038

theano.function()总是需要一个输入列表。如果函数接受0个输入(如本例所示),则需要为输入提供一个空列表。”

f2 = th.function(outputs=z)必须是f2 = th.function([], outputs=z)

相关问题 更多 >

    热门问题