
EN121220190807
Practice makes perfect
import pandas as pd
import tensorflow as tf
import matplotlib.pyplot as plt
Exercise 1: Perform the following equation on the tensor.
R = tf.constant(12, tf.int16, name="twelve")
print(R)
F = tf.constant(4, tf.int16, name="twelve")
print(F)
KOT = tf.div (R, F)
print(KOT)
with tf.Session() as sess:
result_2 = KOT.eval()
print(result_2)
sess = tf.Session()
print(sess.run(KOT))
Exercise 2: Perform the following equation on the tensor
F = tf.constant(8)
R = tf.constant(2)
FFT = tf.multiply (F, R)
sess = tf.Session()
print(sess.run(FFT))
with tf.Session() as sess:
result_2 = FFT.eval()
print(result_2)
Exercise 3: Mathematical operations on tensors
A = tf.constant(5)
B = tf.constant(2)
PKO = tf.pow(A, B)
sess = tf.Session()
print(sess.run(PKO))
Exercise 4: Mathematical operations on tensors
You do not need to specify the data type because tensorflow alone guesses what type of data was used in the constant.
A = tf.constant(15.9)
B = tf.constant(2.1)
SKO = tf.subtract(A, B)
sess = tf.Session()
print(sess.run(SKO))
Exercise 5: Perform the following equation on the tensor
Tensorflow does not like to have different data formats.
We create a mathematical formula in Python:
A = tf.constant(1.7, tf.float32)
B = tf.constant(2.4, tf.float32)
C = tf.constant(15, tf.float32)
SZK = tf.add(tf.subtract(A, B), C)
sess = tf.Session()
print(sess.run(SZK))
Exercise 5: Perform the following equation on the tensor
Tensorflow does not like to have different data formats.
We create a mathematical formula in Python:
A = tf.constant(2.07)
B = tf.constant(1.3)
C = tf.constant(2.7)
SSF = tf.subtract(A, B)
PKO = tf.pow(SSF,C)
with tf.Session() as sess:
result_2 = PKO.eval()
print(result_2)
Exercise 6: Mathematical operations on tensors
We create a mathematical formula in Python:
We can use the math library resources:
https://docs.python.org/3/library/math.html
import math
a = math.pi
a
C = tf.constant(2.1)
D = tf.constant(math.pi)
GG = tf.multiply(C, D)
PKK = tf.sqrt(GG)
with tf.Session() as sess:
result_2 = PKK.eval()
print("The x value sought is: ",result_2)
Exercise 7: actions on Tensorflow tensors
Please calculate in Tensorflow the value of n:
Let’s check how much it will be:
math.pow(15,(1/3))
In Tensorflow, be careful about the fixed format.
C = tf.constant(15, tf.float32)
A = tf.constant(3, tf.float32)
H = tf.constant(1, tf.float32)
G = tf.div(H,A)
PK = tf.pow(C,G)
with tf.Session() as sess:
result_2 = G.eval()
print(result_2)
with tf.Session() as sess:
result_2 = PK.eval()
print(result_2)
Exercise 8: actions on Tensorflow tensors
Please calculate in Tensorflow the value of n:
We can use the math library resources: https://docs.python.org/3/library/math.html
math.e
math.pow(math.e,(1/4))
C = tf.constant(math.e, tf.float32)
A = tf.constant(4, tf.float32)
H = tf.constant(1, tf.float32)
G = tf.div(H,A)
ZHP = tf.pow(C,G)
with tf.Session() as sess:
result_2 = ZHP.eval()
print(result_2)
Exercise 9. Change of the tensor type from float to int
TensorFlow automatically selects the data type when the argument is not specified when creating the tensor.
PKP = tf.constant(3.123456789, tf.float32)
ZNP = tf.cast(PKP, dtype=tf.int32)
print(PKP.dtype)
print(ZNP.dtype)