#!/usr/bin/env python # coding: utf-8 # # Operations on a Computational Graph # # We start by loading the necessary libraries and resetting the computational graph. # In[2]: import os import matplotlib.pyplot as plt import numpy as np import tensorflow as tf from tensorflow.python.framework import ops ops.reset_default_graph() # ### Start a graph session # In[3]: sess = tf.Session() # ### Create tensors # In[4]: # Create data to feed in the placeholder x_vals = np.array([1., 3., 5., 7., 9.]) # Create the TensorFlow Placceholder x_data = tf.placeholder(tf.float32) # Constant for multilication m = tf.constant(3.) # We loop through the input values and print out the multiplication operation for each input. # In[5]: # Multiplication prod = tf.multiply(x_data, m) for x_val in x_vals: print(sess.run(prod, feed_dict={x_data: x_val})) # ### Output graph to Tensorboard # In[6]: merged = tf.summary.merge_all(key='summaries') if not os.path.exists('tensorboard_logs/'): os.makedirs('tensorboard_logs/') my_writer = tf.summary.FileWriter('tensorboard_logs/', sess.graph) # ![Operations on a Graph](https://github.com/nfmcclure/tensorflow_cookbook/raw/master/02_TensorFlow_Way/images/01_Operations_on_a_Graph.png) # In[ ]: