TensorFlow入门基础知识(五)tf.add_n()的用法

版权声明:转载请标明附带连接标明出处 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 1 Tensor objects of the same type in: float32float64int64int32uint8int16int8complex64qint8quint8qint32. Must all be the same size and shape.
  • name: A name for the operation (optional).

Returns:

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]

猜你喜欢

转载自blog.csdn.net/Hollake/article/details/79704129