In [1]:
import numpy as np
import matplotlib.pyplot as plt

%matplotlib inline
In [2]:
# Create a vector
vec = np.array([[5],[4]])
print(vec)
[[5]
 [4]]
In [3]:
origin = np.zeros(vec.shape)

plt.figure(figsize=(6,6))
plt.quiver(*origin, *vec, color=['r'], scale=1, units='xy')

plt.grid()
plt.xlim(-10,10)
plt.ylim(-10,10)
plt.gca().set_aspect('equal')
plt.show()
In [4]:
x_coord = vec[0]
y_coord = vec[1]

print("x:", x_coord)
print("y:", y_coord)
x: [5]
y: [4]
In [5]:
# As shown in the theory above, if we multiply vectors i and j by scalar 
# we will get a vector. Let's see how we can reconstruct the original vector
# if we know the amount of movement over x and y axis.

i = np.array([[1],[0]])
j = np.array([[0],[1]])

vec_new = i*x_coord + j*y_coord
print(vec_new)
[[5]
 [4]]