Dot product / Inner product / Scalar product
Algebraic Definition Geometric Definition Python Code from matplotlib.pyplot import plot point1 = [0, 0] point2 = [3, 0] x_values = [point1[0], point2[0]] y_values = [point1[1], point2[1]] plot(x_values, y_values, 'b-') # format: Blue dashes point1 = [0, 0] point2 = [3, 3] x_values = [point1[0], point2[0]] y_values = [point1[1], point2[1]] plot(x_values, y_values, color='red', marker='o') import numpy as np a = np.array([3, 0]) b = np.array([3, 3]) c = np.array([1, 1]) print("a, b, c:", a, b, c, end = "\n\n") print("a.dot(b):", a.dot(b)) print("b.dot(a):", b.dot(a), end = "\n\n") print("np.dot(a, b):", np.dot(a, b)) print("sum(a*b):", sum(a*b), end = "\n\n") print("np.dot(b, c):", np.dot(b, c)) print("sum(b*c):", sum(b*c), end = "\n\n") theta = np.pi / 4 print("theta = np.pi / 4") print("np.linalg.norm(a) * np.linalg.norm(b) * np.cos(theta):", np.linalg.norm(a) * np.linalg.norm(b) * np.cos(theta)) a, b, c: [3 0] [3 3] [1 1] a.dot(b): 9 b.dot(a): 9 np.dot(a, b): 9 sum(a*b): 9 np.dot(b, c): 6 sum(b*c): 6 theta = np.pi / 4 np.linalg.norm(a) * np.linalg.norm(b) * np.cos(theta): 9.0
Friday, September 3, 2021
Dot Product using Python, NumPy, Matplotlib
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment