2016-04-10 33 views
2
import numpy as np 
from numpy.linalg import inv 
import theano.tensor as T 
from theano.compile import function 
from theano.tensor.nlinalg import matrix_inverse, det 
from theano import shared 
from theano import config 

A = shared(np.matrix('1 0 0; 1 2 0; 0 0 3', dtype=config.floatX)) 
print(A.get_value()) 
invA = matrix_inverse(A) 
print(invA) 

print(invA)語句輸出「MatrixInverse.0」。矩陣確實有倒數。有人可以幫我打印矩陣逆? 在此先感謝。Theano Matrix Inverse

回答

1

你缺少一個Theano函數來計算符號矩陣求逆

A = T.dmatrix('A') 
invA = matrix_inverse(A) 
f = theano.function([A], invA) 
print(f(np.matrix('1 0 0; 1 2 0; 0 0 3', dtype=config.floatX))) 
#[[ 1.   0.   0.  ] 
#[-0.5   0.5   0.  ] 
#[ 0.   0.   0.33333333]] 
+0

感謝您的幫助。 – Nira