<jupyter_start><jupyter_text>OperationsThis function introduces various operations in TensorFlowDeclaring Operations<jupyter_code>import matplotlib.pyplot as plt
import numpy as np
import tensorflow as tf
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
from tensorflow.python.framework import ops
ops.reset_default_graph()<jupyter_output>WARNING:tensorflow:From /home/rong/anaconda3/lib/python3.7/site-packages/tensorflow_core/python/compat/v2_compat.py:88: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version.
Instructions for updating:
non-resource variables are not supported in the long term<jupyter_text>Open graph session<jupyter_code>sess = tf.Session()<jupyter_output><empty_output><jupyter_text>Arithmetic OperationsTensorFlow has multiple types of arithmetic functions.  Here we illustrate the differences between `div()`, `truediv()` and `floordiv()`.`div()` : integer of division (similar to base python `//``truediv()` : will convert integer to floats.`floordiv()` : float of `div()`<jupyter_code>print(sess.run(tf.div(3,4)))
print(sess.run(tf.truediv(3,4)))
print(sess.run(tf.floordiv(3.0,4.0)))<jupyter_output>WARNING:tensorflow:From <ipython-input-3-ab8850756d13>:1: div (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Deprecated in favor of operator or tf.math.divide.
0
0.75
0.0<jupyter_text>Mod function:<jupyter_code>print(sess.run(tf.mod(22.0,5.0)))<jupyter_output>2.0<jupyter_text>Cross Product:<jupyter_code>print(sess.run(tf.cross([1.,0.,0.],[0.,1.,0.])))<jupyter_output>[0. 0. 1.]<jupyter_text>Trig functionsSine, Cosine, and Tangent:<jupyter_code>print(sess.run(tf.sin(3.1416)))
print(sess.run(tf.cos(3.1416)))
print(sess.run(tf.div(tf.sin(3.1416/4.), tf.cos(3.1416/4.))))<jupyter_output>-7.2399803e-06
-1.0
1.0000036<jupyter_text>Custom operationsHere we will create a polynomial function:`f(x) = 3 * x^2 - x + 10`<jupyter_code>test_nums = range(15)

def custom_polynomial(x_val):
    # Return 3x^2 - x + 10
    return(tf.subtract(3 * tf.square(x_val), x_val) + 10)

print(sess.run(custom_polynomial(11)))<jupyter_output>362<jupyter_text>What should we get with list comprehension:<jupyter_code>expected_output = [3*x*x-x+10 for x in test_nums]
print(expected_output)<jupyter_output>[10, 12, 20, 34, 54, 80, 112, 150, 194, 244, 300, 362, 430, 504, 584]<jupyter_text>TensorFlow custom function output:<jupyter_code>for num in test_nums:
    print(sess.run(custom_polynomial(num)))<jupyter_output>10
12
20
34
54
80
112
150
194
244
300
362
430
504
584
{'fraction_non_alphanumeric': 0.13340935005701254, 'fraction_numerical': 0.07221588749524896, 'mean_word_length': 7.0, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '311214', 'license': 'MIT', 'n_tokens_mistral': 1123, 'n_tokens_neox': 999, 'n_words': 203, 'path': '01_Introduction/05_Declaring_Operations/05_operations.ipynb', 'repo_name': 'Rong-creator/tensorflow_cookbook', 'size': '2631'}