其他分享
首页 > 其他分享> > 03_矩阵基础

03_矩阵基础

作者:互联网

#placeholder
import tensorflow as tf
data1 = tf.placeholder(tf.float32)
data2 = tf.placeholder(tf.float32)
dataAdd = tf.add(data1,data2)
with tf.Session() as sess:
    print(sess.run(dataAdd,feed_dict={data1:55,data2:60}))
print("end!")
import tensorflow as tf
data1 = tf.constant([[2,5]])
data2 = tf.constant([[55,52],
                   [99,85]])
data3 = tf.constant([[5,8,9],
                   [5,66,52],
                   [88,17,4]])
print(data3.shape)  #维数
with tf.Session() as sess:
    print(sess.run(data2))  #打印出所有的行和列
    print(sess.run(data3[:,0])) #打印第一列
    print(sess.run(data3[0,:]))  #打印第一行
    print(sess.run(data3[2,2]))  #打印矩阵的第十三行,第三列
import tensorflow as tf
mat0 = tf.zeros(5,6)
mat1 = tf.constant([[5,8,6],
                  [56,52,6],
                  [66,5,56]])
mat2 = tf.zeros_like(mat1)
mat3 = tf.ones(2,3)
mat4 = tf.fill([8,8],23)
mat5 = tf.linspace(0.0,2.0,11)
mat6 = tf.random_uniform([2,2],-5,6)
with tf.Session() as sess:
    print(sess.run(mat0))
    print(sess.run(mat1))
    print(sess.run(mat2))
    print(sess.run(mat3))
    print(sess.run(mat4))
    print(sess.run(mat5))
    print(sess.run(mat6))

标签:03,sess,run,基础,矩阵,print,tf,data3,data2
来源: https://blog.51cto.com/u_14229365/2923912