1、首先,实现张量的创建:
from keras.layers import add
import tensorflow as tf
a = [[1],[2],[5],[7]]
at = tf.convert_to_tensor(a,dtype=float)
print('at:')
print(at)
b = [[3],[4],[3],[6]]
bt = tf.convert_to_tensor(b,dtype=float)
print('bt:')
print(bt)
2、其次,计算两个张量的和,即用add函数:
f = add([at,bt])
print('f:')
print(f)
此时打印出来的是张量f的大小和数据类型

3、最后,需要显示出张量的具体数值,需要用到eval函数:
with tf.Session() as sess:
print(f.eval())
必须在tf.Session()下使用,否则出错。
