1

One of my Theano functions does not take any inputs and only uses shared variables to calculate the output. But this function throws a TypeError: function() takes at least 1 argument (1 given).

Here a minimal example:

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)
4

1 回答 1

1

来自:https ://stackoverflow.com/a/16782594/380038

theano.function()总是需要一个输入列表。如果函数采用 0 输入,就像在这种情况下,您需要为输入提供一个空列表。”

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

于 2013-05-28T08:29:27.513 回答