import tensorflow as tf mat0 = tf.constant([[0,0,0],[0,0,0]])#两行三列 mat1 = tf.zeros([2,3]) mat2 = tf.ones([3,2]) mat3 = tf.fill([2,3],15) with tf.Session() as sess: print(sess.run(mat0)) print(sess.run(mat1)) print(sess.run(mat2)) print(sess.run(mat3))
import tensorflow as tf mat1 = tf.constant([[2],[3],[4]]) mat2 = tf.zeros_like(mat1) mat3 = tf.linspace(0.0,2.0,11) mat4 = tf.random_uniform([2,3],-1,2) with tf.Session() as sess: print(sess.run(mat2)) print(sess.run(mat3)) print(sess.run(mat4))