How to compare two arrays using tensorflow?

南楼画角 提交于 2021-02-08 05:08:34

问题


I need to compare two arrays and get either true or false,not elementwise result. My code is

X = tf.constant([0.05, 0.10], dtype=tf.float32, shape=[1, 2])
y = tf.constant([0.01, 0.99], dtype=tf.float32, shape=[1, 2])

equality = tf.equal(X, y)

prints [False, False]

my requirement is to get true or false, not an array.


回答1:


Assuming that you want to return False if any of your values are not equal then you can use the reduce_all operation:

equality = tf.math.reduce_all(tf.equal(X, y))



回答2:


I got solution.

equality = tf.equal(X, y)   
reduce_t = tf.reduce_all(equality)
print(sess.run(reduce_t))


来源:https://stackoverflow.com/questions/56394240/how-to-compare-two-arrays-using-tensorflow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!