矩阵 python 加法
In the python code, we will add two Matrices. We can add two Matrices only and only if both the matrices have the same dimensions. For our code, we consider the matrices with dimensions 4x3.
在python代码中,我们将添加两个矩阵。 仅当两个矩阵的维数相同时,我们才可以添加两个矩阵。 对于我们的代码,我们考虑尺寸为4x3的矩阵。
矩阵加法的Python代码 (Python code for matrix addition)
# Linear Algebra Learning Sequence
# Matrix Addition
import numpy as np
# Use of np.array() to define a matrix
V1 = np.array([[1,2,3],[2,3,5],[3,6,8],[323,623,823]])
V2 = np.array([[965,2413,78],[223,356,500],[312,66,78],[42,42,42]])
print("--The Matrixa A-- \n", V1)
print("--The Matrix B-- \n", V2)
sem = V1 + V2
print("\n---A + B--- \n", sem)
Output:
输出:
--The Matrixa A--
[[ 1 2 3]
[ 2 3 5]
[ 3 6 8]
[323 623 823]]
--The Matrix B--
[[ 965 2413 78]
[ 223 356 500]
[ 312 66 78]
[ 42 42 42]]
---A + B---
[[ 966 2415 81]
[ 225 359 505]
[ 315 72 86]
[ 365 665 865]]
翻译自: https://www.includehelp.com/python/matrix-addition.aspx
矩阵 python 加法