首页 > 编程知识 正文

矩阵 python 加法矩阵加法 使用Python的线性代数,线性代数矩阵乘法公式

时间:2023-05-03 22:58:58 阅读:264814 作者:3052

矩阵 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 Additionimport numpy as np# Use of np.array() to define a matrixV1 = 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 + V2print("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 加法

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。