0

I have four tensor objects, e.g., A, B, C, and D (see below).

A: <tf.Tensor 'mul_388:0' shape=(5,) dtype=float32>
B: <tf.Tensor 'mul_396:0' shape=(5,) dtype=float32>
C: <tf.Tensor 'clip_by_value_30:0' shape=(5,) dtype=float32>
D: <tf.Tensor 'clip_by_value_31:0' shape=(5,) dtype=float32>

I have to create new tensor object E based on the conditions given below:

E = C when A <= B
else
E = D

What is the best way to do it? I am using Tensorflow version 2.9.1.

I tried following but didn't work.

E = C[A <= B]
E = D[A > B]

1 Answer 1

1

Use tf.cond:

E = tf.cond(A <= B, true_fn=lambda: C, false_fn=lambda: D)
Sign up to request clarification or add additional context in comments.

2 Comments

Can also do E = tf.where(A <= B, C, D)
For me, E = tf.where(A <= B, C, D) worked fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.