convert python ndarray to theano tensor type variable

我只是一个虾纸丫 提交于 2019-12-10 19:06:37

问题


I have ndarray like :

diag = []
diag.append(np.diag([1,1,0]))
diag.append(np.diag([0,1,1]))
diag
  [array([[1, 0, 0],
   [0, 1, 0],
   [0, 0, 0]]), array([[0, 0, 0],
   [0, 1, 0],
   [0, 0, 1]])]

How can I convert it into Theano tensor variable of type float 64, matrix ? As I need to perform dot operation like

Theano.dot(diag, X) where X is shared variable of type float 64, matrix.

回答1:


Just create a SharedVariable like this

diag_ = theano.shared(np.array(diag).astype("float64"))
theano.dot(diag_, X)

http://deeplearning.net/software/theano/library/compile/shared.html



来源:https://stackoverflow.com/questions/41198973/convert-python-ndarray-to-theano-tensor-type-variable

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