Guest User

Untitled

a guest
Jan 20th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. import tensorflow as tf
  2.  
  3.  
  4. # Constants (3-element arrays).
  5. a = tf.constant([100, 200, 300])
  6. b = tf.constant([1, 2, 3])
  7.  
  8. # Use placeholder for predicate to where.
  9. # ... We pass in an array of 3 bools to fill the placeholder.
  10. j = tf.placeholder(tf.bool, [3])
  11.  
  12. # Use where to apply 1 of 2 methods based on each predicate.
  13. # ... First argument is the predicate (contains bools).
  14. # Second argument is run when true.
  15. # Third argument is run when false.
  16. x = tf.where(j, a + 5000, a + b)
  17.  
  18. # Run with 3 bools in placeholder.
  19. array_temp = [False, True, False]
  20. result = tf.Session().run(x, {j: array_temp})
  21.  
  22. # For false, add 2 elements toe get her.
  23. # ... For true, add 5000 to first element.
  24. print(result)
  25.  
  26. ## Output
  27.  
  28. ## [ 101 5200 303]
Add Comment
Please, Sign In to add comment