预先定义好的数据不能满足要求,需要实时插入的数据
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:1,data2:2}))
#1 dataAdd 2 data(feed_dict={:,:})
import tensorflow as tf
data1=tf.constant([[6,6]])#一行两列
data2=tf.constant([[2],[2]])#两行一列
data3=tf.constant([[1,2],[3,4],[5,6]])#三行两列
print(data3.shape)
with tf.Session() as sess:
print(sess.run(data3[0]))#打印第一行
print(sess.run(data3[:,0]))#打印第一列
矩阵运算
import tensorflow as tf
data1 = tf.constant([[6,6]])#1*2类型
data2 = tf.constant([[2],
[2]])#2*1类型
data3 = tf.constant([[3,3]])
data4 = tf.constant([[1,2],
[3,4],
[5,6]])
matMul = tf.matmul(data1,data2)
matMul2 = tf.multiply(data1,data2)
matAdd = tf.add(data1,d