對(duì)Tensorflow中的矩陣運(yùn)算函數(shù)詳解
tf.diag(diagonal,name=None) #生成對(duì)角矩陣
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ù)相反,返回對(duì)角陣的對(duì)角元素
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) #求一個(gè)2維Tensor足跡,即為對(duì)角值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 #運(yùn)算前是否轉(zhuǎn)置
a_is_sparse=False,b_is_sparse=False #a,b是否當(dāng)作系數(shù)矩陣進(jìn)行運(yùn)算
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) #計(jì)算行列式
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決定計(jì)算前是否進(jìn)行轉(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) #對(duì)輸入方陣cholesky分解,即為將一個(gè)對(duì)稱正定矩陣表示成一個(gè)下三角矩陣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]]
以上這篇對(duì)Tensorflow中的矩陣運(yùn)算函數(shù)詳解就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
jupyter關(guān)于pandas的dataframe行列顯示不全與復(fù)原問(wèn)題
這篇文章主要介紹了jupyter關(guān)于pandas的dataframe行列顯示不全與復(fù)原問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-02-02Python數(shù)據(jù)結(jié)構(gòu)之二叉排序樹的定義、查找、插入、構(gòu)造、刪除
這篇文章主要給大家介紹了關(guān)于Python數(shù)據(jù)結(jié)構(gòu)之二叉排序樹應(yīng)用的相關(guān)資料,二叉排序樹又稱為二叉查找樹,它或者是一顆空樹,或者是具有下列性質(zhì)的二叉樹,需要的朋友可以參考下2021-06-06docker django無(wú)法訪問(wèn)redis容器的解決方法
今天小編就為大家分享一篇docker django無(wú)法訪問(wèn)redis容器的解決方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-08-08Python文件系統(tǒng)模塊pathlib庫(kù)
這篇文章介紹了Python中的文件系統(tǒng)模塊pathlib庫(kù),文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-05-05Django?logging日志模塊實(shí)例詳解(日志記錄模板配置)
Django使用python自帶的logging作為日志打印工具,下面這篇文章主要給大家介紹了Django?logging日志模塊(日志記錄模板配置)的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-08-08用Python編寫一個(gè)基于終端的實(shí)現(xiàn)翻譯的腳本
這篇文章主要介紹了用Python編寫一個(gè)基于終端的實(shí)現(xiàn)翻譯的腳本,代碼基于Python2.x,需要的朋友可以參考下2015-04-04Python實(shí)現(xiàn).gif圖片拆分為.png圖片的簡(jiǎn)單示例
有時(shí)候需要把GIF圖片分解成一張一張的靜態(tài)圖,jpg或者png格式,下面這篇文章主要給大家介紹了關(guān)于Python實(shí)現(xiàn).gif圖片拆分為.png圖片的相關(guān)資料,需要的朋友可以參考下2023-01-01Python實(shí)現(xiàn)剪刀石頭布小游戲(與電腦對(duì)戰(zhàn))
這篇文章給大家分享Python基礎(chǔ)實(shí)現(xiàn)與電腦對(duì)戰(zhàn)的剪刀石頭布小游戲,練習(xí)if while輸入和輸出,代碼簡(jiǎn)單易懂,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2019-12-12