tf.add_n 将列表元素相加

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

posted @ 2020-03-06 13:40  小娜子成长记  阅读(701)  评论(0编辑  收藏  举报