<jupyter_start><jupyter_text>Enterprise Deep Learning with TensorFlow: openSAP  SAP Innovation Center Network```Licensed under the Apache License, Version 2.0 (the "License");you may not use this file except in compliance with the License.You may obtain a copy of the License at    http://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.```  Introduction to TensorFlowIn this notebook, we will learn - Some common TensorFlow operations - Run math operations using Session- Understand how TensorFlow can run computes on different devices<jupyter_code># Import tensorflow library
# Reference it as tf for ease of calling
import tensorflow as tf
# Let's check our TensorFlow version
print("You are running TensorFlow %s" % str(tf.__version__))
# List of math ops can be found here: https://www.tensorflow.org/api_guides/python/math_ops
# Let us use an InteractiveSession 
# Provides an easy to use session for interactive environments like a Jupyter notebook
sess = tf.InteractiveSession()
a = tf.constant(23, name='const_a')
b = tf.constant(11, name='const_b')

# Let's add the two prime numbers
c = tf.add(a, b)
print(c.eval())
# Let's subtract two prime numbers
c = tf.subtract(a, b)
print(c.eval())
# More ops for playing with TensorFlow 
# Let's multiply two prime numbers
c = tf.multiply(a, b)
# 253

# Let's divide two prime numbers
c = tf.divide(23, 13)
# 2

a = tf.constant(23., name='const_a')
b = tf.constant(11., name='const_b')

# Now, let's divide two prime numbers to see the difference
c = tf.divide(23, 13)
# 2.090909

# Let's get the modulus of two prime numbers
c = tf.mod(a, b)
# 1.0

a = tf.constant(2., name='const_a')
b = tf.constant(10., name='const_b')

# Let's calculate 2^10
c = tf.pow(a, b)
# 1024.0

# List of control ops can be found here: https://www.tensorflow.org/api_guides/python/control_flow_ops
# Check for a < b
c = tf.less(a, b)
# True 

# Check for a <= b
c = tf.less_equal(a, b)
# True

# Check for a > b
c = tf.greater(a, b)
# False

# Check for a >= b
c = tf.greater_equal(a, b)
# False

# Some conditional check statements
c = tf.logical_and(True, False)
# False

tf.logical_or(True, False)
# True

tf.logical_xor(True, False)
# True
# Let's create two matrices, a 3x1 and another 1x3 matrix for multiplication
mat_a = tf.constant([[1., 3., 5.]], name='mat_a')
mat_b = tf.constant([[7.], [11.], [13.]], name='mat_b')
# Let's matrix multiply the two matrices
prod_op = tf.matmul(mat_a, mat_b)
print(prod_op)
# Create a session object to run our matrix multiplication
sess = tf.Session()
# Get the result by calling run on the session
# Returns an numpy ndarray object
mat_mul = sess.run(prod_op)
# Let's view the result 
print(mat_mul)
# [[ 105.]]
# Remember to close the session when done, releases the resources
sess.close()
# Easier way to handle session objects is 
# using the familiar 'with' block as follows
with tf.Session() as sess:
    mat_mul = sess.run(prod_op)
    print(mat_mul)
# [[ 105.]]
# If you have multiple devices capable of computes, use it as follows
# /cpu:<device_id>
# [Mac] Run the following command to know how many logical cores are present on your machine: sysctl -n hw.ncpu
# [Win] Run the following command to know how many logical cores are present on your machine: systeminfo | find /i "processors"
with tf.Session() as sess:
    with tf.device("/cpu:0"):
        mat_mul = sess.run(prod_op)
        print(mat_mul)
# [[ 105.]]<jupyter_output>[[105.]]
{'fraction_non_alphanumeric': 0.10799892270401293, 'fraction_numerical': 0.01858335577699973, 'mean_word_length': 4.367052023121388, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 3, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '8668', 'license': 'Apache-2.0', 'n_tokens_mistral': 1261, 'n_tokens_neox': 1179, 'n_words': 470, 'path': 'Week_01_Unit_05.ipynb', 'repo_name': 'DGCoach/jupyter', 'size': '3713'}