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)
From: https://stackoverflow.com/a/16782594/380038
" theano.function()
always needs a list of inputs. If the function takes 0 input, like in this case, you need to give an empty list for the inputs."
f2 = th.function(outputs=z)
has to be f2 = th.function([], outputs=z)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.