對Tensorflow中的矩陣運算函數(shù)詳解
tf.diag(diagonal,name=None) #生成對角矩陣
import tensorflowas tf; diagonal=[1,1,1,1] with tf.Session() as sess: print(sess.run(tf.diag(diagonal)))
#輸出的結(jié)果為[[1 0 0 0]
[0 1 0 0]
[0 0 1 0]
[0 0 0 1]]
tf.diag_part(input,name=None) #功能與tf.diag函數(shù)相反,返回對角陣的對角元素
import tensorflow as tf; diagonal =tf.constant([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]) with tf.Session() as sess: print(sess.run(tf.diag_part(diagonal)))
#輸出結(jié)果為[1,1,1,1]
tf.trace(x,name=None) #求一個2維Tensor足跡,即為對角值diagonal之和
import tensorflow as tf; diagonal =tf.constant([[1,0,0,3],[0,1,2,0],[0,1,1,0],[1,0,0,1]]) with tf.Session() as sess: print(sess.run(tf.trace(diagonal)))#輸出結(jié)果為4
tf.transpose(a,perm=None,name='transpose') #調(diào)換tensor的維度順序,按照列表perm的維度排列調(diào)換tensor的順序
import tensorflow as tf;
diagonal =tf.constant([[1,0,0,3],[0,1,2,0],[0,1,1,0],[1,0,0,1]])
with tf.Session() as sess:
print(sess.run(tf.transpose(diagonal))) #輸出結(jié)果為[[1 0 0 1]
[0 1 1 0]
[0 2 1 0]
[3 0 0 1]]
tf.matmul(a,b,transpose_a=False,transpose_b=False,a_is_sparse=False,b_is_sparse=False,name=None) #矩陣相乘
transpose_a=False,transpose_b=False #運算前是否轉(zhuǎn)置
a_is_sparse=False,b_is_sparse=False #a,b是否當(dāng)作系數(shù)矩陣進行運算
import tensorflow as tf; A =tf.constant([1,0,0,3],shape=[2,2]) B =tf.constant([2,1,0,2],shape=[2,2]) with tf.Session() as sess: print(sess.run(tf.matmul(A,B)))
#輸出結(jié)果為[[2 1] [0 6]]
tf.matrix_determinant(input,name=None) #計算行列式
import tensorflow as tf; A =tf.constant([1,0,0,3],shape=[2,2],dtype=tf.float32) with tf.Session() as sess: print(sess.run(tf.matrix_determinant(A)))
#輸出結(jié)果為3.0
tf.matrix_inverse(input,adjoint=None,name=None)
adjoint決定計算前是否進行轉(zhuǎn)置
import tensorflow as tf; A =tf.constant([1,0,0,2],shape=[2,2],dtype=tf.float64) with tf.Session() as sess: print(sess.run(tf.matrix_inverse(A)))
#輸出結(jié)果為[[ 1. 0. ] [ 0. 0.5]]
tf.cholesky(input,name=None) #對輸入方陣cholesky分解,即為將一個對稱正定矩陣表示成一個下三角矩陣L和其轉(zhuǎn)置的乘積德分解
import tensorflow as tf; A =tf.constant([1,0,0,2],shape=[2,2],dtype=tf.float64) with tf.Session() as sess: print(sess.run(tf.cholesky(A)))
#輸出結(jié)果為[[ 1. 0. ] [ 0. 1.41421356]]
以上這篇對Tensorflow中的矩陣運算函數(shù)詳解就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
python pandas模塊進行數(shù)據(jù)分析
Python的Pandas模塊是一個強大的數(shù)據(jù)處理工具,可以用來讀取、處理和分析各種數(shù)據(jù),本文主要介紹了python pandas模塊進行數(shù)據(jù)分析,具有一定的參考價值,感興趣的可以了解一下2024-01-01
Python學(xué)習(xí)筆記之open()函數(shù)打開文件路徑報錯問題
這篇文章主要介紹了Python學(xué)習(xí)筆記之open()函數(shù)打開文件路徑報錯問題,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-04-04
python中pd.cut()與pd.qcut()的對比及示例
本文主要介紹了python中pd.cut()與pd.qcut()的對比及示例,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-06-06
python?playwright?庫上傳和下載操作(自動化測試?playwright)
這篇文章主要介紹了python?playwright?庫上傳和下載操作(自動化測試?playwright?),playwright中的上傳和下載比selenium的上傳和下載要簡便些,本文結(jié)合實例代碼給大家介紹的非常詳細,需要的朋友可以參考下2023-05-05

