国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

對Tensorflow中的矩陣運算函數詳解

2020-01-04 14:47:27
字體:
來源:轉載
供稿:網友

tf.diag(diagonal,name=None) #生成對角矩陣

import tensorflowas tf;diagonal=[1,1,1,1]with tf.Session() as sess:  print(sess.run(tf.diag(diagonal))) 
 #輸出的結果為[[1 0 0 0]    [0 1 0 0]    [0 0 1 0]    [0 0 0 1]]

tf.diag_part(input,name=None) #功能與tf.diag函數相反,返回對角陣的對角元素

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)))
#輸出結果為[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)))#輸出結果為4

tf.transpose(a,perm=None,name='transpose') #調換tensor的維度順序,按照列表perm的維度排列調換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))) #輸出結果為[[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 #運算前是否轉置

a_is_sparse=False,b_is_sparse=False #a,b是否當作系數矩陣進行運算

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)))
#輸出結果為[[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))) 
#輸出結果為3.0

tf.matrix_inverse(input,adjoint=None,name=None)

adjoint決定計算前是否進行轉置

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)))
#輸出結果為[[ 1. 0. ]   [ 0. 0.5]]

tf.cholesky(input,name=None) #對輸入方陣cholesky分解,即為將一個對稱正定矩陣表示成一個下三角矩陣L和其轉置的乘積德分解

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)))
#輸出結果為[[ 1.   0.  ]   [ 0.   1.41421356]]

以上這篇對Tensorflow中的矩陣運算函數詳解就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到python教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 宁远县| 屏山县| 吉林市| 石狮市| 邵阳县| 阿合奇县| 文山县| 安泽县| 平阴县| 墨竹工卡县| 云南省| 临沧市| 石狮市| 新源县| 泰安市| 北安市| 鄂温| 赤城县| 应城市| 内丘县| 义乌市| 青田县| 大冶市| 吉林市| 桐城市| 晋中市| 东平县| 邵武市| 益阳市| 栖霞市| 垣曲县| 威宁| 屯门区| 资兴市| 无棣县| 清镇市| 苍南县| 岳阳县| 永靖县| 新乡县| 璧山县|