tensorflow api中描述如下
A Tensor. Has the same type as inputs.
tf.add_n(inputs, name=None)
Add all input tensors element wise.
Args:
inputs: A list of at least 1 Tensor 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]
本文介绍了TensorFlow中tf.add_n函数的使用方法及其参数设置,通过实例演示了如何将多个相同类型和形状的张量进行元素级相加。实验部分展示了如何创建张量并使用该函数实现加法运算。
1121

被折叠的 条评论
为什么被折叠?



