fork download
  1.  
  2. import tensorflow as tf
  3.  
  4. tf.compat.v1.enable_eager_execution() # Enable eager execution for TensorFlow 1.x compatibility mode
  5.  
  6. # Step 1: Define inputs
  7. x = tf.constant(2.0)
  8. y = tf.constant(3.0)
  9.  
  10. # Step 2: Define operations
  11. z = tf.add(x, y) # z = x + y
  12. w = tf.multiply(z, 2.0) # w = 2 * z
  13.  
  14. # Step 3: Define variables
  15. weights = tf.Variable(initial_value=0.5)
  16. output = tf.multiply(w, weights) # output = w * weights
  17.  
  18. # Step 4: Execute and print the result
  19. print("Output:", output.numpy())
  20.  
Success #stdin #stdout 1.39s 201716KB
stdin
Standard input is empty
stdout
('Output:', 5.0)