簡體   English   中英

Theano TypeError:function()至少接受1個參數(給定1個)

[英]Theano TypeError: function() takes at least 1 argument (1 given)

我的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)

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

theano.function()始終需要一個輸入列表。如果該函數接受0個輸入(在這種情況下,則需要為輸入提供一個空列表)。”

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM