Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TensorFlow equivalent of numpy.all()

Tags:

tensorflow

As stated in the title, is there a TensorFlow equivalent of the numpy.all() function to check if all the values in a bool tensor are True? What is the best way to implement such a check?

like image 678
Bruno KM Avatar asked Aug 17 '17 13:08

Bruno KM


1 Answers

Use tf.reduce_all, as follows:

import tensorflow as tf
a=tf.constant([True,False,True,True],dtype=tf.bool)
res=tf.reduce_all(a)
sess=tf.InteractiveSession()
res.eval()

This returns False.

On the other hand, this returns True:

import tensorflow as tf
a=tf.constant([True,True,True,True],dtype=tf.bool)
res=tf.reduce_all(a)
sess=tf.InteractiveSession()
res.eval()
like image 58
Miriam Farber Avatar answered Nov 20 '22 16:11

Miriam Farber