2

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.

Nija I Pillai
  • 1,046
  • 11
  • 13

2 Answers2

3

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))
Stewart_R
  • 13,764
  • 11
  • 60
  • 106
2

I got solution.

equality = tf.equal(X, y)   
reduce_t = tf.reduce_all(equality)
print(sess.run(reduce_t))
Nija I Pillai
  • 1,046
  • 11
  • 13