Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tensorflow as tf
- # Constants (3-element arrays).
- a = tf.constant([100, 200, 300])
- b = tf.constant([1, 2, 3])
- # Use placeholder for predicate to where.
- # ... We pass in an array of 3 bools to fill the placeholder.
- j = tf.placeholder(tf.bool, [3])
- # Use where to apply 1 of 2 methods based on each predicate.
- # ... First argument is the predicate (contains bools).
- # Second argument is run when true.
- # Third argument is run when false.
- x = tf.where(j, a + 5000, a + b)
- # Run with 3 bools in placeholder.
- array_temp = [False, True, False]
- result = tf.Session().run(x, {j: array_temp})
- # For false, add 2 elements toe get her.
- # ... For true, add 5000 to first element.
- print(result)
- ## Output
- ## [ 101 5200 303]
Add Comment
Please, Sign In to add comment