tf.add_n([p1, p2, p3....])函数是实现一个列表的元素的相加。就是输入的对象是一个列表,列表里的元素可以是向量,矩阵
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]) with tf.Session() as sess: sess.run(tf.initialize_all_variables()) print sess.run(input1 + input2) print sess.run(output)
输出:
[ 1.68921876 2.73008633 3.04061747]
[ 1.68921876 2.73008633 3.04061747]
https://blog.csdn.net/UESTC_C2_403/article/details/72808839?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task