矩阵形状| 使用Python的线性代数

Prerequisite: Linear Algebra | Defining a Matrix

先决条件: 线性代数| 定义矩阵

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. Therefore, knowing the dimensions of the matrices turns out to be one of the major steps in Linear Algebra. The following code shows how an inbuilt function can be used to achieve our goal of the shape of a Matrix.

在python代码中,我们将添加两个矩阵。 仅当两个矩阵的维数相同时,我们才可以添加两个矩阵。 因此,了解矩阵的维数成为线性代数的主要步骤之一。 以下代码展示了如何使用内置函数来实现矩阵形状的目标。

查找矩阵形状的Python代码 (Python code for fidning Shape of Matrix)

# Linear Algebra Learning Sequence
# Shape of Matrix 

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,44],[223,356,500,44],[312,66,78,44],[42,42,42,44],[44,44,44,44]])

print("--The Matrixa A-- \n",V1)
print("\n--The Matrix B-- \n",V2)

print("\n\n Shape of the matrix A: ", V1.shape)
print(" Shape of the matrix B: ", V2.shape)

Output:

输出:

--The Matrixa A-- 
 [[  1   2   3]
 [  2   3   5]
 [  3   6   8]
 [323 623 823]]

--The Matrix B-- 
 [[ 965 2413   78   44]
 [ 223  356  500   44]
 [ 312   66   78   44]
 [  42   42   42   44]
 [  44   44   44   44]]


 Shape of the matrix A:  (4, 3)
 Shape of the matrix B:  (5, 4)


翻译自: https://www.includehelp.com/python/shape-of-matrix.aspx

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值