- Vector operations
- Multiplication
- Vector-vector multiplication
- Matrix-vector multiplication
- Matrix-matrix multiplication
- Identity matrix
- Inverse
u = np.array([2, 7, 5, 6])
v = np.array([3, 4, 8, 6])
# addition
u + v
# subtraction
u - v
# scalar multiplication
2 * v
def vector_vector_multiplication(u, v):
assert u.shape[0] == v.shape[0]
n = u.shape[0]
result = 0.0
for i in range(n):
result = result + u[i] * v[i]
return result
def matrix_vector_multiplication(U, v):
assert U.shape[1] == v.shape[0]
num_rows = U.shape[0]
result = np.zeros(num_rows)
for i in range(num_rows):
result[i] = vector_vector_multiplication(U[i], v)
return result
def matrix_matrix_multiplication(U, V):
assert U.shape[1] == V.shape[0]
num_rows = U.shape[0]
num_cols = V.shape[1]
result = np.zeros((num_rows, num_cols))
for i in range(num_cols):
vi = V[:, i]
Uvi = matrix_vector_multiplication(U, vi)
result[:, i] = Uvi
return result
I = np.eye(3)
V = np.array([
[1, 1, 2],
[0, 0.5, 1],
[0, 2, 1],
])
inv = np.linalg.inv(V)
Add notes here (PRs are welcome).
The notes are written by the community. If you see an error here, please create a PR with a fix. |