출처 : www.boostcourse.org/ai222
Vector
Matrix
Matrix addition
Matrix Product
# Vector
u = [2, 2]
v = [2, 3]
z = [3, 5]
result = [sum(t) in zip(u, v, z)]
print(result)
# Scalar-Vector product
u = [1, 2, 3]
v = [4, 5, 6]
alpha = 2
result = [for z in zip(u, v)]
print(result)
# Matrix addition
matrix_a = [[3, 6], [4, 5]]
matrix_a = [[5, 8], [3, 7]]
result = [[sum(row) for row in zip(*t)] for t in zip(matrix_a, matrix_b)]
print(result)
# Scalar-Matrix Product
matrix_a = [[3, 6], [4, 5]]
alpha = 4
result = [[alpha * element for element in t] for t in matrix_a]
print(result)
# Matrix Transpose
matrix_a = [[1, 2, 3], [4, 5, 6]]
result = [[element for element in t] for t in zip(*matrix_a)]
# Matrix Product
matrix_a = [[1, 1, 2], [2, 1, 1]]
matrix_b = [[1, 1], [2, 1], [1, 3]]
result = [[sum(a * b for a, b in zip(row_a, column_b))
for column_b in zip(*matrix_b)] for row_a in matrix_a]
print(result)
'개발 > 수학' 카테고리의 다른 글
[선형대수학] Eigenvectors and Eigenvalues 고유벡터와 고유값 (0) | 2023.10.06 |
---|---|
[선형대수학] Least Squares - 실습 (0) | 2023.10.06 |
[선형대수학] Least Squares Problem - Orthogonal Projection (0) | 2023.10.06 |
[선형대수학] Least squares - Normal Equation 정규방정식 (1) | 2023.10.04 |
[선형대수학] Least squares 최소자승법 (1) | 2023.10.04 |