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. The Diag function, in contrast, returns the diagonal element of the diagonal array
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足迹, which is the sum of the diagonal values 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的维度顺序 the order in which the tensor is swapped by the dimension of the list perm
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, whether B is calculated as a coefficient matrix
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 (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 deciding whether to transpose before calculation
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分解, that is, to represent a symmetric positive definite matrix as a lower triangular matrix L and its transpose multiply jide decomposition
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]]