Theano-theana-expression-matrix-multiplication
提供:Dev Guides
Theano-行列乗算の式
2つの行列のドット積を計算します。 最初の行列の次元は2 x 3で、2番目の行列の次元は3 x 2です。 入力として使用した行列とその積は、ここで表されます-
変数を宣言する
上記のテアノ式を書くために、私たちはまず、次のように行列を表すために2つの変数を宣言します
a = tensor.dmatrix()
b = tensor.dmatrix()
dmatrixは、doubleの行列のタイプです。 マトリックスサイズはどこにも指定しないことに注意してください。 したがって、これらの変数は任意の次元の行列を表すことができます。
式の定義
ドット積を計算するために、次のように dot と呼ばれる組み込み関数を使用しました-
c = tensor.dot(a,b)
乗算の出力は、 c と呼ばれる行列変数に割り当てられます。
Theano関数の定義
次に、前の例のように式を評価する関数を定義します。
f = theano.function([a,b], c)
関数への入力は、マトリックス型の2つの変数aとbであることに注意してください。 関数の出力は、変数 c に割り当てられます。変数は自動的にマトリックス型になります。
Theano関数の呼び出し
私たちは今、次のステートメントを使用して関数を呼び出します-
d = f([[The two variables in the above statement are NumPy arrays. You may explicitly define NumPy arrays as shown here −
[source,result,notranslate]
f(numpy.array([[numpy.array([[3、-1]、[1,2]、[6,1]]))
After *d *is computed we print its value −
[source,result,notranslate]
印刷する(d)
You will see the following output on the output −
[source,result,notranslate]
[[全プログラムのリスト
The complete program listing is given here:
from theano import*
a = tensor.dmatrix()
b = tensor.dmatrix()
c = tensor.dot(a,b)
f = theano.function([a,b], c)
d = f([[print (d)
プログラム実行のスクリーンショットはここに示されています-