TensorFlow入門基礎知識(五)tf.add_n()の使い方
1217 ワード
tensorflow apiでは次のように記述されています.
A
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.
すべてのテンソル要素を追加
自己実験:
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]