Reputation: 145
I have a tensor 3-D as follow:
A=array([[[False, False, False],
[False, False, True],
[False, True, True],
[ True, True, True],
[ True, True, False]]], dtype=bool)
A.shape= (1,5,3)
I would like to convert it to 2-D tensor in tensorflow in graph where if I have a True in any element the aggregate result should be True, otherwise mush be False. Like follows:
output=array([[False, True, True, True, True]], dtype=bool)
output.shape= (1,5)
Upvotes: 0
Views: 747
Reputation: 1117
This should do exactly what you want (directly from the documentation):
# '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
Upvotes: 1