Import the vector class form the library


In [4]:
from stumpy import Vector

create some vectors to work with

$$ \vec v = \begin{bmatrix}1 \\ 2 \\ 3 \end{bmatrix}, \ \ \ \vec u = \begin{bmatrix}-1 \\ 1 \\ 1 \end{bmatrix} $$

In [5]:
myVec1 = Vector([1,2,3])
myVec2 = Vector([-1,1,1])

Add two vectors together

$$ \vec v + \vec u = \begin{bmatrix}0 \\ 3 \\ 4 \end{bmatrix} $$

In [6]:
print(myVec1 + myVec2)


(0, 3, 4)

Get the unit vector representation of any non-zero vector

$$ \hat{u} = \begin{bmatrix} -0.577 \\ 0.577 \\ 0.577 \end{bmatrix} $$

In [7]:
print(myVec2.getNormalization())


(-0.5773502691896258, 0.5773502691896258, 0.5773502691896258)

Scalar multiplication

$$ 2 \vec v = \begin{bmatrix} 2 \\ 4 \\ 6 \end{bmatrix} $$

In [8]:
print(myVec1 * 2)


(2, 4, 6)

Dot products of vectors


In [9]:
print(myVec1 * myVec2)


4

The difference in angle between two vectors


In [10]:
print(myVec1.angleDiff(myVec2))

# Use degrees instead of radians
print(myVec1.angleDiff(myVec2, units="deg"))


0.9056002717820778
51.887073499013354

Orthogonality


In [11]:
print(Vector([1,2]).orthogonalTo(Vector([2,-1])))


True

Parallelism


In [9]:
print(Vector([-7.579,-7.88]).parallelTo(Vector([0,0])))


True