矩阵 python 加法_矩阵加法| 使用Python的线性代数

本文介绍了如何使用Python进行矩阵加法,重点在于两个矩阵必须有相同的维度,例如4x3的矩阵。给出了矩阵加法的Python代码示例,并展示了运行结果。
摘要由CSDN通过智能技术生成

矩阵 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 加法

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值