np.dot()
np.dot() multiplies vectors or matrices the linear-algebra way.
In this page:
Syntax
np.dot(a, b)
a @ b
np.dot()
For two 1-D arrays it returns the inner product; for 2-D arrays it is matrix multiplication. Inner dimensions must match: (m, n) dot (n, p) gives (m, p). The @ operator is the modern equivalent for matrices.
Note:
dot of two vectors sums the products of matching elements.
Example: np.dot()
import numpy as np
v = np.array([1, 2, 3])
w = np.array([4, 5, 6])
print(np.dot(v, w))
A = np.array([[1, 2], [3, 4]])
B = np.array([[5, 6], [7, 8]])
print(np.dot(A, B))
# Output:
# 32
# [[19 22]
# [43 50]]
Related Topics
Common Mistakes
- Confusing dot with element-wise *
- Multiplying matrices with mismatched inner dimensions
- Assuming order does not matter
Chapter Summary
- dot gives the inner product for vectors
- It is matrix multiplication for 2-D
- Inner dimensions must agree
- Order matters
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: