使用函数调用矩阵的列 使用Python的线性代数

Prerequisite: Linear Algebra | Defining a Matrix

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

Linear algebra is the branch of mathematics concerning linear equations by using vector spaces and through matrices. Matrix is the key to linear algebra.

线性代数是使用向量空间和矩阵的线性方程组的数学分支。 矩阵是线性代数的关键。

All the linear algebra revolves around matrices. Columns are the heart of a Matrix. From column space to null space of a matrix is based on Columns. Therefore, whenever we have to go for Column operations, then we have to call our columns. A function provides a reproducibility feature to the program and therefore it is good to build a function for calling the desired column.

所有线性代数都围绕矩阵旋转。 列是矩阵的核心。 矩阵的从列空间到空空间都是基于列的。 因此,每当必须进行列操作时,就必须调用列。 函数为程序提供了可再现性,因此最好构建一个函数来调用所需的列。

使用函数调用矩阵列的Python代码 (Python code for Calling Column of a Matrix using Function)

# Linear Algebra Learning Sequence
# Calling Column of a Matrix using Function
import numpy as np

# Use of np.array() to define a matrix
V = np.array([[1,2,3],[2,3,5],[3,6,8],[323,623,823]])
print("--The Matrix-- \n", V)

c = int(input("Enter j (column number) : "))

# Defining function for calling column of matrix    
def col(M,c):
    coli = []
    for i in range(len(M)):
        coli.append(M[i][c-1])
    return coli

C = col(V,c)

for i in range(len(C)):
    print("Component [",i,"] [",c-1,"] :", C[i])

Output:

输出:

RUN 1:
--The Matrix-- 
 [[  1   2   3]
 [  2   3   5]
 [  3   6   8]
 [323 623 823]]
Enter j (column number) : 3
Component [ 0 ] [ 2 ] : 3
Component [ 1 ] [ 2 ] : 5
Component [ 2 ] [ 2 ] : 8
Component [ 3 ] [ 2 ] : 823

RUN 2:
--The Matrix-- 
 [[  1   2   3]
 [  2   3   5]
 [  3   6   8]
 [323 623 823]]
Enter j (column number) : 1
Component [ 0 ] [ 0 ] : 1
Component [ 1 ] [ 0 ] : 2
Component [ 2 ] [ 0 ] : 3
Component [ 3 ] [ 0 ] : 323


翻译自: https://www.includehelp.com/python/calling-column-of-a-matrix-using-function.aspx

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值