tensorflow-条件循环控制(2)

tf.tuple(元组)

tf.tuple(
    tensors,
    name=None,
    control_inputs=None
)

将多个tensor合并组。

这创建了一个张量元组,其值与多张量参数相同,只是每个张量的值只有在计算完所有张量的值之后才返回。

control_inputs包含额外的OPS,在OP完成之前必须完成,但其输出不返回。

这可以被用作并行计算的“连接”机制:所有的参数张量可以并行计算,但是在所有并行计算完成之后,元组返回的任何张量的值都是可用的。

.

参数:
tensors: 多tensor的列表或IndexedSlices, 有些条目可能是None。
name: (可选)用作操作的 name_scope的名称。
control_inputs: 在返回之前完成附加操作表
返回:

像tensors一样

Raises:

ValueError:如果tensors没有包括任何tensor或IndexedSlices。
TypeError: 如果control_inputs不是一个Operation或Tensor 对象的列表。

#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Mon Aug 27 11:16:32 2018
@author: myhaspl
"""

import tensorflow as tf
x1 = tf.random_normal([1000,1000],mean=100)
x2 = tf.random_normal([1000,1000],mean=100)
x3 = tf.random_normal([1000,1000],mean=100)

y1 = tf.sqrt(x1)
y2 = tf.sqrt(x2)
y3 = tf.sqrt(x3)
z = tf.tuple([y1,y2,y3])

sess=tf.Session()
with sess: 
    res=sess.run(z)
    print res[0]
[[ 9.989998  9.980425  9.897268 ... 10.010141 10.008263 10.005144]
 [ 9.970587  9.988404 10.011098 ... 10.027785  9.956984 10.110886]
 [ 9.982615  9.952952 10.033136 ...  9.999784 10.009718  9.915539]
 ...
 [ 9.934934  9.926054 10.045075 ... 10.0579   10.020126  9.959899]
 [10.031994 10.059689 10.05442  ... 10.009988  9.977903 10.036525]
 [ 9.945853  9.955557 10.047363 ... 10.067215  9.942139 10.06124 ]]

猜你喜欢

转载自blog.51cto.com/13959448/2325223