【Python】SymPy库——关于矩阵的基本操作和运算

网上有很多关于科学计算包sympy的介绍,这里我把官方文档的英文表述贴过来。简单翻译就是sympy是个代数系统,底层完全使用python语言写的,使用简单、好理解、易扩展。

SymPy is a Python library for symbolic mathematics. It aims to become a full-featured computer algebra system (CAS) while keeping the code as simple as possible in order to be comprehensible and easily extensible. SymPy is written entirely in Python.

正好最近在研究线性代数,顺手把SymPy中关于矩阵的基本用法记录一下。

1、矩阵创建

矩阵的创建过程被理解为提供了一组行向量。 A matrix is constructed by providing a list of row vectors that make up the matrix.

import sympy
matrix_a = sympy.Matrix([[1, 3], [-2, 3]])  # 生成2*2的方阵
matrix_b = sympy.Matrix([[1, 0, 2], [2, 3, 4]])  # 生成2*3的矩形矩阵

2、创建列向量

list对象被理解为一个列向量。 a list of elements is considered to be a column vector.

column_vector_a = sympy.Matrix([1, 2, 1])

3、截取矩阵的某一行或列, 使用 row()和 col()

print(matrix_b.col(0))  # 打印第一列
print(matr
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值