import tensorflow as tf import numpy as np # Create 100 phony x, y data points in NumPy, y = x * 0.1 + 0.3 x_data = np.random.rand(100).astype(np.float32) y_data = x_data * 0.1 + 0.3 # Try to find values for W and b that compute y_data = W * x_data + b # (We know that W should be 0.1 and b 0.3, but TensorFlow will # figure that out for us.) W = tf.Variable(tf.random_uniform([1], -1.0, 1.0)) b = tf.Variable(tf.zeros([1])) y = W * x_data + b # Minimize the mean squared errors. loss = tf.reduce_mean(tf.square(y - y_data)) optimizer = tf.train.GradientDescentOptimizer(0.5) train = optimizer.minimize(loss) # Before starting, initialize the variables. We will 'run' this first. init = tf.initialize_all_variables() # Launch the graph. sess = tf.Session() sess.run(init) # Fit the line. for step in range(201): sess.run(train) if step % 20 == 0: print(step, sess.run(W), sess.run(b)) # Learns best fit is W: [0.1], b: [0.3]# your code goes here
import tensorflow as tf Import numpy as np vector 1 = tf.constant([1.0, 2.0, 3.0]) vector 2 = tf.constant([4.0, 5.0, 6.0]) result = tf.add(vector 1, vector 2) print("Result of vector addition:") print(result.np())
(0, array([0.79902035], dtype=float32), array([-0.13770618], dtype=float32)) (20, array([0.28591508], dtype=float32), array([0.19654357], dtype=float32)) (40, array([0.14802471], dtype=float32), array([0.27327564], dtype=float32)) (60, array([0.1124055], dtype=float32), array([0.2930967], dtype=float32)) (80, array([0.10320453], dtype=float32), array([0.2982168], dtype=float32)) (100, array([0.10082779], dtype=float32), array([0.2995394], dtype=float32)) (120, array([0.10021383], dtype=float32), array([0.29988104], dtype=float32)) (140, array([0.10005523], dtype=float32), array([0.2999693], dtype=float32)) (160, array([0.10001427], dtype=float32), array([0.29999205], dtype=float32)) (180, array([0.1000037], dtype=float32), array([0.29999796], dtype=float32)) (200, array([0.10000096], dtype=float32), array([0.29999948], dtype=float32))
WARNING:tensorflow:From /usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version. Instructions for updating: Colocations handled automatically by placer. WARNING:tensorflow:From /usr/local/lib/python2.7/dist-packages/tensorflow/python/util/tf_should_use.py:193: initialize_all_variables (from tensorflow.python.ops.variables) is deprecated and will be removed after 2017-03-02. Instructions for updating: Use `tf.global_variables_initializer` instead.