03_tf矩阵基础1
2019-07-12 本文已影响0人
犬夜叉写作业
#placehold
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:6,data2:2}))
# 1 dataAdd 2 data (feed_dict = {1:6,2:2})
print('end!')
8.0
end!
#类比 数组 M行N列 [] 内部[] [里面 列数据] [] 中括号整体 行数
#[[6,6]] [[6,6]]
import tensorflow as tf
data1 = tf.constant([[6,6]]) #一行两列
data2 = tf.constant([[2], #两行一列
[2]])
data3 = tf.constant([[3,3]])
data4 = tf.constant([[1,2],
[3,4],
[5,6]])
print(data4.shape)# 维度
with tf.Session() as sess:
print(sess.run(data4)) #打印整体
print(sess.run(data4[0]))# 打印某一行,此处第1行
print(sess.run(data4[:,0]))# 打印某列
print(sess.run(data4[0,1]))
(3, 2)
[[1 2]
[3 4]
[5 6]]
[1 2]
[1 3 5]
2