Linear Algebra Technical Flashcards
Initialize a vector
import numpy as np
np.array([1,2,3]) or np.array([1], [2], [3])
Calculate the magnitude of a vector
np.linalg.norm(v)
Calculate the direction of a vector
Add two vectors
v1 + v2
Scale a vector
3 * v1
Subtract two vectors
v1 - v2
Initialize a zero vector
np.zeros(3)
Get the negative of a vector
-1 * v1
Perform dot product of two vectors
- numpy.matmul(v1, v2)
- v1.dot(v2)
Create a random vector
np.random.rand(3,1)
Calculate the cross product of a vector
a = np.array([1,2,3])
b = np.array([4,5,6])
a.shape # (3,)
b.shape # (3.)
np.cross(a,b)
What is the angle between two vectors
np.arccose(np.dot(a1, a2)/ np.linalg(a1) * np.linalg.norm(a2))
Get the Euclidian distance of a vector
point1 = np.array((1, 2, 3))
point2 = np.array((1, 1, 1))
dist = np.linalg.norm(point1 - point2)
Get the projection of a vector
Projection of the vector = a.b/||b||**2 * b
scalar_projection = np.dot(a,b)/ np.dot(b,b)
vector_projection = scalar_projection * b
Create linearly independent matrix
np.random.randint(10, size=(2,5))