• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

对Tensorflow中的矩阵运算函数详解

python 搞代码 4年前 (2022-01-07) 21次浏览 已收录 0个评论

今天小编就为大家分享一篇对Tensorflow中的矩阵运算函数详解,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

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) #矩阵相乘

tra来源gaodai#ma#com搞*!代#%^码网nspose_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中的矩阵运算函数详解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持gaodaima搞代码网

以上就是对Tensorflow中的矩阵运算函数详解的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:对Tensorflow中的矩阵运算函数详解

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址