You've successfully subscribed to Smartcodehub ™ Blog
Welcome back! You've successfully signed in.

## Machine Learning From scratch | Part 2. Vector Dot Product

Neeraj Dana

Prerequisit : https://blog.smartcodehub.com/machine-learning-from-scratch/

Please watch the video of Scalar and vector

``````a = (1,2,3) and b =(4,-5,6)
a+b = (4,-3,9)``````

### Vector Scalling

``````a = (1,2,3)
2a = (2,4,6)
3a = (3,6,9)
(1/2)a = (0.5,1,1.5)``````

### Vector Dot Product (Scaler Product)

in simple it is combining to vectors to give a scaller number (ei : 1,5,10,6,3,200 ...)

``````a= (a1,a2,a3)
b= (b1,b2,b3)

a.b = (a1*b1 +a2*b2 + a3*b3 )

Lets see it by example
a=(1,2,3)
b=(-2,6-3)

a.b = ((1*-2)+(2*6)+(3*-3)) = (-2+12-9) = 1

Dot product of vector a and vector b = 1 ``````

### Vector Magnitude

``````magnitude of a vector a is = √(a.a) (square root of dot product of the vector by iteself)

a= (1,-4,9)
magnitude of a  = |a| = √(a.a) = √(1 + 16 + 81) = √98``````

### Unit Vectors

``````a= (1,2,3)
a.a = (1*1 + 2*2 + 3*3) = (1+4+9) = 14

magnitude of a = √14

lets have one more vector a' = (1/√14)a

and then when we do
a'.a' = (1/√14)a . (1/√14)a
= (1/14)(a.a)
= (1/14)*14 = 1

this kind of vector (a') which when claculated dot product with same vector gives 1 are know as Unit Vectors
a' is a unit vector

``````

### Angel Between Two Vectors

``````If we have two vectors a and b
a= (-1,0,-1)
b = (4,1,-1)

we know a.b = |a||b|cosθ

a.b = (-4+01) = -3

|a| = √a.a = √(1+0+1) = √2
|b| = √b.b = √(16+1+1) = √18

cosθ = a.b/|a||b| = -3/√2*√18 = -3/√2*3√2 = -1/2
θ = cos'(1/2) = 0.27 (approx)``````
Next : Matrices and Matrices Dot Products