Tensorflow
基础8:张量生成合并与切片
生成
tf.zeros()
tf.ones()
tf.eye()
tf.constant()
random_normal() 标准正态分布
rabdin_uniform 生成均匀分布
tf.matmul() 点积
tf.range()
tf.linespace()
tf.random_normal(shape=(10,), mean=0.0, stddev=1.0)
<tf.Tensor ‘random_normal_2:0’ shape=(10,) dtype=float32>
合并和切片
a = tf.constant([[1,2,3],[1,2,3]])
b = tf.constant([[2,2,3],[1,2,1]])
c = tf.constant(np.random.randint(0,100,(10,5)))
with tf.Session() as sess:
display(sess.run(c))
array([[48, 84, 72, 35, 62],
[91, 28, 82, 20, 9],
[ 3, 0, 14, 84, 87],
[29, 22, 0, 3, 55],
[82, 45, 88, 20, 84],
[79, 86, 95, 4, 6],
[12, 23, 23, 21, 21],
[69, 65, 46, 62, 42],
[47, 77, 95, 33, 53],
[46, 94, 35, 83, 5]])
with tf.Session() as sess:
# print(sess.run([a,b]))
# print(sess.run(a[:-1,:-1]))
crop = tf.random_crop(value=c,size=[1,4])
print(sess.run(crop))
[[28 82 20 9]]