tensorflow 入门之二 - TensorFlow 矩阵相加
import tensorflow as tf
tf.__version__
'1.14.0'
# 定义第一个矩阵
vec_1=tf.constant([1,2,3,4])
# 定义第二个矩阵
vec_2=tf.constant([7,8,9,10])
vec_1,vec_2
(<tf.Tensor 'Const:0' shape=(4,) dtype=int32>,
<tf.Tensor 'Const_1:0' shape=(4,) dtype=int32>)
tf.Tensor: 表明他是 Tensor
Const_6:0: tf 标识,说明其类型是 Const, 6:0 随着运行次数的增加而增加
shape=(4,): 矩阵的类型,说明是一维向量,有 4 个值
dtype=int32: 数据类型是 int32
# 定义加法
ver_add=tf.add(vec_1,vec_2)
ver_add
<tf.Tensor 'Add:0' shape=(4,) dtype=int32>
tf.Tensor: 表明他是 Tensor
Add_1:0: tf 标识,说明其类型是 Add , 1:0 随着运行次数的增加而增加
shape=(4,): 矩阵的类型,说明是一维向量,有 4 个值
dtype=int32: 数据类型是 int32
# 运行上面的定义
with tf.Session() as se:
print(se.run(ver_add))
[ 8 10 12 14]
运行结果是两个向量的和
[1,2,3,4]
[7,8,9,10]
=
[ 8 10 12 14]