问题
I tried the code below:
x=T.dvector('x')
y=T.dvector('y')
input=[x,y]
s=T.sum(x**2+y**2)
f=theano.gradient.hessian(s,wrt=input)
h=function(input,f)
Then I run it with following real values
x=[1,2]
y=[1,2]
h([x,y]
Then I encountered following error
TypeError: ('Bad input argument to theano function with name "<ipython-input-115-32fd257c46ad>:7" at index 0(0-based)', 'Wrong number of dimensions: expected 1, got 2 with shape (2L, 2L).')
I am new to python and am exploring Theano for building neural networks.
回答1:
h
is a function that accepts two parameters. You are giving it a single parameter which is a list containing two elements.
Try changing h([x,y])
to h(x,y)
.
来源:https://stackoverflow.com/questions/30500332/how-to-use-theano-gradient-hessian-example-needed