矩阵形状| 使用Python的线性代数
Prerequisite: Linear Algebra | Defining a Matrix
先決條件: 線性代數(shù)| 定義矩陣
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代碼中,我們將添加兩個(gè)矩陣。 僅當(dāng)兩個(gè)矩陣的維數(shù)相同時(shí),我們才可以添加兩個(gè)矩陣。 因此,了解矩陣的維數(shù)成為線性代數(shù)的主要步驟之一。 以下代碼展示了如何使用內(nèi)置函數(shù)來(lái)實(shí)現(xiàn)矩陣形狀的目標(biāo)。
查找矩陣形狀的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
總結(jié)
以上是生活随笔為你收集整理的矩阵形状| 使用Python的线性代数的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 凯立德导航多少钱啊?
- 下一篇: python 忽略 异常_如何忽略Pyt