View source on GitHub |
Groups tensors together.
tf.tuple(
tensors, control_inputs=None, name=None
)
The returned tensors have the same value as the input tensors, but they are computed only after all the input tensors have been computed.
See also tf.group
and tf.control_dependencies
.
Example:
with tf.Graph().as_default():
with tf.compat.v1.Session() as sess:
v = tf.Variable(0.0)
a = tf.constant(1.0)
sess.run(tf.compat.v1.global_variables_initializer())
for i in range(5):
update_op = v.assign_add(1.0)
b = a + v
res_b = sess.run(b)
res_v = sess.run(v)
print(res_v)
0.0
0.0
0.0
0.0
0.0
with tf.Graph().as_default():
with tf.compat.v1.Session() as sess:
v = tf.Variable(0.0)
a = tf.constant(1.0)
sess.run(tf.compat.v1.global_variables_initializer())
for i in range(5):
update_op = v.assign_add(1.0)
calc = [a + v]
# `tf.tuple` ensures `update_op` is run before `b`
b = tf.tuple(calc, [tf.group(update_op)])
res_b = sess.run(b)
res_v = sess.run(v)
print(res_v)
1.0
2.0
3.0
4.0
5.0
Returns | |
---|---|
Same as tensors .
|
Raises | |
---|---|
ValueError
|
If tensors does not contain any Tensor or IndexedSlices .
|
TypeError
|
If control_inputs is not a list of Operation or Tensor
objects.
|