在张量流中聚合张量的每个元素
Aggregate each element of tensor in tensorflow
我有一个 3-D 张量如下:
A=array([[[False, False, False],
[False, False, True],
[False, True, True],
[ True, True, True],
[ True, True, False]]], dtype=bool)
A.shape= (1,5,3)
我想将它转换为图中张量流中的二维张量,如果
我在任何元素中都有一个 True 聚合结果应该是 True,否则必须是 False。如下:
output=array([[False, True, True, True, True]], dtype=bool)
output.shape= (1,5)
这应该完全符合您的要求(直接来自文档):
# 'x' is [[True, True]
# [False, False]]
tf.reduce_any(x) ==> True
tf.reduce_any(x, 0) ==> [True, True]
tf.reduce_any(x, 1) ==> [True, False] <== this is what you need
https://www.tensorflow.org/versions/r0.7/api_docs/python/math_ops.html#reduce_any
我有一个 3-D 张量如下:
A=array([[[False, False, False],
[False, False, True],
[False, True, True],
[ True, True, True],
[ True, True, False]]], dtype=bool)
A.shape= (1,5,3)
我想将它转换为图中张量流中的二维张量,如果 我在任何元素中都有一个 True 聚合结果应该是 True,否则必须是 False。如下:
output=array([[False, True, True, True, True]], dtype=bool)
output.shape= (1,5)
这应该完全符合您的要求(直接来自文档):
# 'x' is [[True, True]
# [False, False]]
tf.reduce_any(x) ==> True
tf.reduce_any(x, 0) ==> [True, True]
tf.reduce_any(x, 1) ==> [True, False] <== this is what you need
https://www.tensorflow.org/versions/r0.7/api_docs/python/math_ops.html#reduce_any