"> This work comes from[LearningTensorFlow.com](http://learningtensorflow.com/), developed by[dataPipeline](http://datapipeline.co.au/), with whom the copyright remains. \n",
"For more tutorials and extended exercises, please see the website."
"TensorFlow is a way of representing computation without actually performing it until asked. In this sense, it is a form of lazy computing, and it allows for some great improvements to the running of code:\n",
"\n",
"- Faster computation of complex variables\n",
"- Distributed computation across multiple systems, including GPUs.\n",
"- Reduced redundency in some computations"
]
},
{
"cell_type":"markdown",
"metadata":{},
"source":[
"Let’s have a look at this in action. First, a very basic python script:"
"This script basically just says “create a variable x with value 35, set the value of a new variable y to that plus 5, which is currently 40, and print it out”. The value 40 will print out when you run this program. If you aren’t familiar with python, create a new text file called `basic_script.py`, and copy that code in. Save it on your computer and run it with:\n",
"\n",
"```bash\n",
"python basic_script.py\n",
"```\n",
"\n",
"Note that the path (i.e.`basic_script.py`) must reference the file, so if it is in theCodefolder, you use:\n",
"\n",
"```\n",
"python Code/basic_script.py\n",
"```\n",
"\n",
"Also, make sure you have activated the Anaconda virtual environment. On Linux, this will make your prompt look something like:\n",
"\n",
"```\n",
"(tensorenv)username@computername:~$\n",
"```\n",
"\n",
"If that is working, let’s convert it to a TensorFlow equivalent."
"After running this, you’ll get quite a funny output, something like ```<tensorflow.python.ops.variables.Variable object at 0x10f2fe850>```. This is clearly not the value 40.\n",
"- Create a constant value called x, and give it the numerical value 35\n",
"- Create a Variable called y, and define it as being the equation x + 5\n",
"- Print out the equation object for y\n",
"\n",
"The subtle difference is that y isn’t given “the current value of x + 5” as in our previous program. Instead, it is effectively an equation that means “when this variable is computed, take the value of x (as it is then) and add 5 to it”. The computation of the value of y is never actually performed in the above program.\n",
"We have removed the `print(y)` statement, and instead we have code that creates a session, and actually computes the value of y. This is quite a bit of boilerplate, but it works like this:\n",
"7. Run just the variable y and print out its current value\n",
"\n",
"The step 4 above is where some magic happens. In this step, a graph is created of the dependencies between the variables. In this case, the variable y depends on the variable x, and that value is transformed by adding 5 to it. Keep in mind that this value isn’t computed until step 7, as up until then, only equations and relations are computed."