How to use theano.gradient.hessian? Example needed

2019-08-10 20:55发布

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条回答
来,给爷笑一个
2楼-- · 2019-08-10 21:59

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

查看更多
登录 后发表回答