Creating square matrix with eigenvalues on the diagonal in theano

孤街浪徒 提交于 2019-12-11 10:29:53

问题


I would like to create a square matrix with the eigenvalues on the diagonal:

eigen_values, eigen_vectors = theano.tensor.nlinalg.eig(covariance_matrix)
D = T.nlinalg.AllocDiag(eigen_values)

However apparently theano does not treat the D matrix I created as a standard matrix, thus I cannot use it in the succeding computations.

theano.tensor.var.AsTensorError: ('Cannot convert <theano.tensor.nlinalg.AllocDiag object at 0x7face5708450> to TensorType', <class 'theano.tensor.nlinalg.AllocDiag'>)

回答1:


You're using an operation class as if it were an operation function.

Instead of

D = T.nlinalg.AllocDiag(eigen_values)

try

D = T.nlinalg.AllocDiag()(eigen_values)

or

D = T.nlinalg.alloc_diag(eigen_values)


来源:https://stackoverflow.com/questions/30692742/creating-square-matrix-with-eigenvalues-on-the-diagonal-in-theano

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!