Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Distance Between Vectors

Scalar product of vectors Manhattan distance between vector


In import numpy as np In import numpy as np
from scipy.spatial import distance
dot_value1 = np.dot(vector1, vector2)
dot_value2 = vector1@vector2 d = distance.cityblock(a, b)

Euclidean distance between vectors


In import numpy as np
from scipy.spatial import distance

d = distance.euclidean(a, b)

Indices of mimimum and maximum elements in array


In index = np.array(distances).argmin() # minimum element index
index = np.array(distances).argmax() # maximum element index

Creating class
In class ClassName:
def fit(self, arg1, arg2, ...): # class method
# method content

Theory
Scalar product Class
is an operation resulting in a number (scalar), that is equal is a new data type with its own methods and attributes.
to the sum of element-by-element products of two vectors’
elements Manhattan distance or city block distance
is the sum of modules of coordinate differences of vectors
Euclidian distance a = (x1, x2, ..., xn) и b = (y1, y2, ..., yn):
between vectors a = (x1, x2, ..., xn) и b = (y1, y2, ..., yn) is
the sum of squared differences of coordinates:

You might also like