Reputation: 171
I have two tf arrays of float32, I am taking logical_and operation between the two arrays
tf.math.logical_and(b, a)
Here, I got the error - TypeError: Input 'x' of 'LogicalAnd' Op has type float32 that does not match expected type of bool.
How can I solve this?
Upvotes: 2
Views: 625
Reputation: 26708
Your tensors a
and b
need to be boolean tensors if you plan to use tf.math.logical_and
. Check the docs. This will not work:
import tensorflow as tf
a = tf.constant([5,4,3,2], dtype=tf.float32)
b = tf.constant([5,6,7,8], dtype=tf.float32)
c = tf.math.logical_and(b, a)
Something like this will work:
import tensorflow as tf
a = tf.constant([5,4,3,2], dtype=tf.float32)
b = tf.constant([5,6,7,8], dtype=tf.float32)
a = tf.cast(tf.boolean_mask(a, [True, False, True, False]), dtype=tf.bool)
b = tf.cast(tf.boolean_mask(b, [True, False, True, False]), dtype=tf.bool)
print(tf.math.logical_and(b, a))
Just make sure the tensors are booleans.
Upvotes: 2