import tensorflow as tf #矩阵类型 myzero = tf.zeros([3,5]) #定义3行5列的0矩阵 myones = tf.ones([2,3]) #定义2行3列的矩阵 myfill = tf.fill([3,3],15) #定义3行3列的填充矩阵,填充值为15 myli = tf.linspace(0.0,5.,15) #0到5等分为15份 random_mat = tf.random_uniform([2,3],-2,5) #定义2行3列的-2到5的随机矩阵 data1 = tf.constant([[1,3],[2,5],[3,6]]) data2 = tf.constant([[1,2]]) data3 = tf.constant([[3],[4]]) data4 = tf.constant([[2,2]]) myadd = tf.add(data2,data4) #矩阵加法 mymul = tf.matmul(data2,data3) #矩阵乘法 mymultiply = tf.multiply(data2,data3) #矩阵直接相乘 print(data1.shape) # print(data1[0,:]) with tf.Session() as sess: # print(sess.run(myzero)) # print() # print(sess.run(myones)) # print() # print(sess.run(myfill)) # print() # print(sess.run(mymul)) # print() # print(sess.run(myadd)) # print() # print(sess.run(mymultiply)) # print(sess.run([mymul,myadd,mymultiply])) #一次run多个 # print(sess.run(myli)) print(sess.run(random_mat))