# Import NumPy
import numpy as np
# A vector can be represented as a NumPy array
# Create a one-dimensional vector
vec = np.array([5,1,3])
print(vec)
# Create a two-dimensional vector
vec = np.array([[5,1,3],[2,1,4]])
print(vec)
import matplotlib.pyplot as plt
vec1 = np.array([1,5])
vec2 = np.array([4,-2])
x_vec1 = vec1[0]
y_vec1 = vec1[1]
x_vec2 = vec2[0]
y_vec2 = vec2[1]
vec = np.array([[x_vec1, x_vec2], [y_vec1, y_vec2]])
origin = np.zeros(vec.shape) # origin point
plt.figure(figsize=(6,6))
plt.quiver(*origin, *vec, color=['r','g','b'], scale=1, units='xy')
plt.grid()
plt.xlim(-10,10)
plt.ylim(-10,10)
plt.gca().set_aspect('equal')
plt.show()
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure(figsize=(6,6))
ax = fig.gca(projection='3d')
# Create a three-dimensional vector
# The first vector will be [7 7 7]
# The second vector will be [-5 2 2]
vec = np.array([[7,-5],[7,2],[7,2]])
origin = np.zeros(vec.shape) # origin point
ax.quiver(*origin, *vec)
plt.grid()
ax.set_zlim3d(-10, 10)
ax.set_ylim3d(-10, 10)
ax.set_xlim3d(-10, 10)
plt.show()