TensorFlow入门基础知识(五)tf.add_n()的用法
·
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]
AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。
更多推荐


所有评论(0)