Question: # Distance Calculation # # Create a tensor among the following types : float 3 2 , float 6 4 , complex 6 4 ,

# Distance Calculation
#
# Create a tensor among the following types : float32, float64, complex64, complex128
# Mentioned link details the meaning of each variable :
# create two tensors of shape 2x3.
tensor_a = tf.constant([[1,2,3],[4,5,6]], dtype=tf.float32, name='template')
tensor_b = tf.constant([[1,1,1],[1,1,1]], dtype=tf.float32, name='template')
# 1. Calculating euclidean distance or the l2 norm.
eucledian_distance = tf.norm(tensor_a - tensor_b, ord ='euclidean', axis=None, keepdims=None)
tf.print("Euclidean distance:", eucledian_distance)
# 2. Calculating the Manhattan distance
manhattan_distance = tf.norm(tensor_a - tensor_b, ord =1, axis=None, keepdims=None)
tf.print("Manhattan distance:", manhattan_distance)
# 1. Calculating Euclidean Distance
def euclidean_distance(tensor_1, tensor_2):
# %%%%%%%%%%%%%% implement your code below (1 line)%%%%%%%%%%%%%%
euc_distance =
# %%%%%%%%%%%%%% your code ends here %%%%%%%%%%%%%%
return euc_distance
# 2. Calculating Manhattan distance
def manhattan_distance(tensor_1, tensor_2):
# %%%%%%%%%%%%%% implement your code below (1 line)%%%%%%%%%%%%%%
manh_distance =
# %%%%%%%%%%%%%% your code ends here %%%%%%%%%%%%%%
return manh_distance
tf.print("Euclidean distance:", euclidean_distance(tensor_a, tensor_b))
tf.print("Manhattan distance:", manhattan_distance(tensor_a, tensor_b))

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!