Skip to content

Instantly share code, notes, and snippets.

@fedden
Last active November 7, 2017 19:38
Show Gist options
  • Save fedden/b83587c441738b0b5b89b13a1c1208b4 to your computer and use it in GitHub Desktop.
Save fedden/b83587c441738b0b5b89b13a1c1208b4 to your computer and use it in GitHub Desktop.
Orthogonal Vectors
>>> import numpy as np
>>> # Two vectors, a and b.
>>> a = np.array([-3, 4])
>>> b = np.array([4, 3])
>>> # The dot product is 0.
>>> a.dot(b)
0
>>> # For drawing the origin of the arrows.
>>> origin = np.array([0, 0])
>>> # Plot the vectors using matplotlib.
>>> plt.figure()
>>> ax = plt.gca()
>>> ax.quiver(origin, origin, a, b, angles='xy', scale_units='xy', scale=1)
>>> ax.axis('equal')
>>> ax.set_xlim([-5, 5])
>>> ax.set_ylim([-5, 5])
>>> plt.draw()
>>> plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment