tf的基本知识--matrix操作
#导入tf 开启会话
import tensorflow as tf
sess = tf.Session()
#矩阵 -对角线矩阵
identity_matrix = tf.diag([1,1,1.0])
print(sess.run(identity_matrix))
[[1. 0. 0.]
[0. 1. 0.]
[0. 0. 1.]]
- # 截取矩阵 ,
A = tf.truncated_normal([2,3])
print(sess.run(A))
[-0.81737727 -1.7079943 0.3242292 ]
[-0.54095584 -1.149905 -0.90140224]]
# 充填矩阵
B = tf.fill([2,3],5.0)
print(sess.run(B))
[[5. 5. 5.]
[5. 5. 5.]]
[[0.59499943 0.20474374]
[0.8694447 0.11033809]
[0.54311955 0.5681305 ]]
随机均一分布矩阵
C = tf.random_uniform([3,2])
print(sess.run©)
[[0.59499943 0.20474374]
[0.8694447 0.11033809]
[0.54311955 0.5681305 ]]
# 数组 转 矩阵 tsr
import numpy as np
d = np.array([[1,2,3.0],