版权声明:转载请标明附带连接标明出处 https://blog.csdn.net/Hollake/article/details/79704129
tensorflow api中描述如下
tf.add_n(inputs, name=None)
Add all input tensors element wise.
Args:
inputs
: A list of at least 1Tensor
objects of the same type in:float32
,float64
,int64
,int32
,uint8
,int16
,int8
,complex64
,qint8
,quint8
,qint32
. Must all be the same size and shape.name
: A name for the operation (optional).
Returns:
A Tensor
. Has the same type as inputs
.
添加所有张量元素
自己实验:
import tensorflow as tf;
import numpy as np;
input1 = tf.constant([1.0, 2.0, 3.0])
input2 = tf.Variable(tf.random_uniform([3]))
output = tf.add_n([input1, input2])
init_op = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init_op)
print(sess.run(input1))
print(sess.run(input2))
print(sess.run(output))
结果:
[1. 2. 3.]
[0.6231705 0.50447917 0.28593874]
[1.6231705 2.5044792 3.2859387]