Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert python ndarray to theano tensor type variable

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.
like image 249
Shyamkkhadka Avatar asked Mar 26 '26 20:03

Shyamkkhadka


1 Answers

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

like image 140
basaundi Avatar answered Mar 29 '26 11:03

basaundi