欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程语言 > python >内容正文

python

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

发布时间:2023/12/1 python 56 豆豆
生活随笔 收集整理的这篇文章主要介绍了 矩阵形状| 使用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

总结

以上是生活随笔为你收集整理的矩阵形状| 使用Python的线性代数的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。