对Tensorflow中的矩阵运算函数详解
技术  /  管理员 发布于 7年前   142
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中的矩阵运算函数详解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
122 在
学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号