<jupyter_start><jupyter_text>![Big Data University](https://ibm.box.com/shared/static/jvcqp2iy2jlx2b32rmzdt0tx8lvxgzkp.png)   "Hello World" in TensorFlow  - Exercise Notebook  Before everything, let's import the TensorFlow library<jupyter_code>%matplotlib inline
import tensorflow as tf<jupyter_output><empty_output><jupyter_text>First, try to add the two constants and print the result.<jupyter_code>a = tf.constant([5])
b = tf.constant([2])<jupyter_output><empty_output><jupyter_text>create another TensorFlow object applying the sum (+) operation:<jupyter_code>#Your code goes here<jupyter_output><empty_output><jupyter_text>Click here for the solution 1Click here for the solution 2```c=a+b``````c=tf.add(a,b)```<jupyter_code>with tf.Session() as session:
    result = session.run(c)
    print "The addition of this two constants is: {0}".format(result)<jupyter_output><empty_output><jupyter_text>--- Now let's try to multiply them.<jupyter_code># Your code goes here. Use the multiplication operator.<jupyter_output><empty_output><jupyter_text>Click here for the solution 1Click here for the solution 2```c=a*b``````c=tf.multiply(a,b)```<jupyter_code>with tf.Session() as session:
    result = session.run(c)
    print "The Multiplication of this two constants is: {0}".format(result)<jupyter_output><empty_output><jupyter_text>Multiplication: element-wise or matrix multiplicationLet's practice the different ways to multiply matrices:- **Element-wise** multiplication in the **first operation** ;- **Matrix multiplication** on the **second operation**  ;<jupyter_code>matrixA = tf.constant([[2,3],[3,4]])
matrixB = tf.constant([[2,3],[3,4]])
# Your code goes here<jupyter_output><empty_output><jupyter_text>Click here for the solution```first_operation=tf.multiply(matrixA, matrixB)second_operation=tf.matmul(matrixA,matrixB)```<jupyter_code>with tf.Session() as session:
    result = session.run(first_operation)
    print "Element-wise multiplication: \n", result

    result = session.run(second_operation)
    print "Matrix Multiplication: \n", result<jupyter_output><empty_output><jupyter_text>--- Modify the value of variable b to the value in constant a:<jupyter_code>a=tf.constant(1000)
b=tf.Variable(0)
init_op = tf.global_variables_initializer()
# Your code goes here<jupyter_output><empty_output><jupyter_text>Click here for the solution```a=tf.constant(1000)b=tf.Variable(0)init_op = tf.global_variables_initializer()update = tf.assign(b,a)with tf.Session() as session:    session.run(init_op)     session.run(update)     print(session.run(b))``` --- Fibonacci sequenceNow try to do something more advanced. Try to create a __fibonnacci sequence__ and print the first few values using TensorFlow:If you don't know, the fibonnacci sequence is defined by the equation: $$F_{n} = F_{n-1} + F_{n-2}$$Resulting in a sequence like: 1,1,2,3,5,8,13,21...<jupyter_code><jupyter_output><empty_output><jupyter_text>Click here for the solution 1Click here for the solution 2```a=tf.Variable(0)b=tf.Variable(1)temp=tf.Variable(0)c=a+bupdate1=tf.assign(temp,c)update2=tf.assign(a,b)update3=tf.assign(b,temp)init_op = tf.initialize_all_variables()with tf.Session() as s:	s.run(init_op)	for _ in range(15):		print(s.run(a))		s.run(update1)		s.run(update2)		s.run(update3)``````f = [tf.constant(1),tf.constant(1)]for i in range(2,10):	temp = f[i-1] + f[i-2]	f.append(temp)with tf.Session() as sess:	result = sess.run(f)	print result``` --- Now try to create your own placeholders and define any kind of operation between them:<jupyter_code># Your code goes here<jupyter_output><empty_output><jupyter_text>Click here for the solution```a=tf.placeholder(tf.float32)b=tf.placeholder(tf.float32)c=2*a -bdictionary = {a:[2,2],b:[3,4]}with tf.Session() as session:	print session.run(c,feed_dict=dictionary)```  Try changing our example with some other operations and see the result.Some examples of functions:  tf.multiply(x, y)tf.div(x, y)tf.square(x)tf.sqrt(x)tf.pow(x, y)tf.exp(x)tf.log(x)tf.cos(x)tf.sin(x) You can also take a look at [more operations]( https://www.tensorflow.org/versions/r0.9/api_docs/python/math_ops.html)<jupyter_code>a = tf.constant(5.)
b = tf.constant(2.)<jupyter_output><empty_output><jupyter_text>create a variable named **`c`** to receive the result an operation (at your choice):<jupyter_code>#your code goes here<jupyter_output><empty_output><jupyter_text>Click here for the solution```c=tf.sin(a)```<jupyter_code>with tf.Session() as session:
    result = session.run(c)
    print "c =: {}".format(result)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14285714285714285, 'fraction_numerical': 0.017090271691498685, 'mean_word_length': 6.952961672473868, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 57, 'https://': 2, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '14', 'dir': 'jupyter-structured-clean-dedup', 'id': '75214', 'license': 'MIT', 'n_tokens_mistral': 1654, 'n_tokens_neox': 1588, 'n_words': 358, 'path': 'cognitive class - deep learning tensorflow/.ipynb_checkpoints/ML0120EN-1.1-Exercise-TensorFlowHelloWorld-checkpoint.ipynb', 'repo_name': 'fotavio16/PycharmProjects', 'size': '4564'}