向量/矩阵类-改进了rref并修复了一个错误。添加了作者信息。

linear-algebra-ulloa的Python项目详细描述


线性代数ulloa

在python 3+中使用rest格式的docstring实现向量和矩阵类

总平面图

向量类模仿线性代数中的m x 1向量 包含许多用于处理向量和与向量交互的有用函数。

应该使用get(索引)直接从向量获取值 函数或[]运算符,因为内存中的comp矢量位置可能随函数而变化 像mag()或zero()(改变当前向量comp的那些)。

class Vector

__init__(comp)          - takes in a list of components or a valid mx1 Matrix

resize(length)          - while preserving current elements or filling with 0's, changes current vector length

set(comp, index=-1)     - sets entire list at once or one specific index/value

get(index)              - returns item at specified index of vector

zero()                  - turns the current vector into a zero vector and returns it

mag()                   - returns the magnitude of current vector

normalize(change=False) - returns normalized current vector, if change=True, internal vector is updated

same_normalized(other)  - returns True/False depending on equality of the two vectors once normalized

dot(other)              - returns the dot product of th two vectors

cross(other)            - returns the cross product of u x v (u is current vector, v is other)

perp(other)             - returns True/False if current and other are/aren't perpendicular

parallel(other)         - returns True/False if current and other are/aren't parallel

indep(other)          - returns True/False if curr vector and other vector(s) are linearly independent

operator +              - returns sum of two vectors, component wise addition

operator -              - returns difference of two vectors, component wise subtraction

operator *              - alternate for dot product, or can use for vector scaling

operator **             - returns original vector with its components raised to power

operator ==             - checks to see if lists are equal

to string method        - format: "<elem1, elem2, ...>"

len() method            - can use len() to get vector length

get and set []          - user can get and set values in vector with index based operations []


comp = vector composition, list of components

length = number of components in vector

rows = same as length, used with cols for backwards compatibility with Matrix

cols = 1 (num of columns)

矩阵类模仿线性代数中的矩阵概念,并允许 以不同的方式处理和交互矩阵和向量。

直接从向量中获取值应该使用get(row,col)完成。 函数或[],[]运算符,因为矩阵组件在内存中的位置可能随函数而改变 改变了基础数据类型。

class Matrix

__init__(comp)          - takes in a list of components or a valid Vector

resize(rows, cols)      - while preserving current elements or filling with 0's, changes current vector length

set(comp, index=None)   - sets entire list at once or one specific index/value (tuple or array as (row, col))

get(row=None,col=None)  - can get a specific row, column, or entire matrix composition (no args for matrix)

zero()                  - replaces values in current matrix with all zeroes and returns it

det()                   - takes the determinant of the current NxN matrix

transpose()             - transposes the current mxn matrix to an nxm matrix (1st row becomes 1st col, etc.)

row_echelon()           - returns the current matrix in row echelon form

row_reduce()            - returns the current matrix to reduced row echelon form

identity(n)             - static method that returns the nxn identity matrix

combine(first, second)  - static method that combines two matrices by concatenation

inverse()               - returns the inverse of current nxn matrix, or None if singular

operator +              - returns sum of two matrices, component wise addition

operator -              - returns difference of two matrices, component wise subtraction

operator *              - matrix multiplication, matrix-vector product, scalar multiplication

operator **             - returns original matrix with its components raised to power

operator ==             - checks to see if internal lists are equal

to string method        - format: "[row1\n row2\n row3\n ...]" and floats are shown as fractions

len() method            - returns tuple formatted as (row, col)

get and set [][]        - can get rows and specific values with [] or [][], and set specific values with [][]


comp = matrix composition, list of lists where each list is a row

rows = number of rows in matrix

cols = number of columns in matrix

测试

有一个用于编写测试的文件。目前,这只是一系列的断言。将来,我将更新测试文件,以使用更标准化的版本/库进行测试。

文档字符串/文档

整个图书馆都有详尽的文件。python库包含一个help()函数,可用于查看特定类/方法的docstring。

类:帮助(类名)

方法:帮助(classname.methodname)

例如,帮助(vector.resize)显示…

resize(self, length)

    Re-sizes the vector to the specified length. If length is greater than

    current size, the new components are initialized with 0, otherwise if length

    is less than current size, the last few components are lost.

    :param length: new length of vector

    :type length: int

    :return: current vector, now resized

    :rtype: Vector

反之亦然。帮助(向量)和帮助(矩阵)返回主要类概述。

使用库

管道:

pip install linear-algebra-ulloa

pip3 install linear-algebra-ulloa

使用

from linear_lib.linear import *

能够创建和利用向量和矩阵类 线性。向量或线性。矩阵前缀。

未来图书馆可能增加的内容

向量类

  • 检查当前向量和其他向量是否正交的方法

  • 支持使用matplotlib或类似库绘制/绘制一定数量的二维或三维矢量

  • 交叉产品

矩阵类

  • 行列式

  • 行缩减矩阵

  • 求矩阵的逆

  • 转置矩阵

  • 用最小二乘逼近</P>拟合直线的独立函数
  • 作为矩阵类一部分的一般最小二乘法

附加

  • 使用[][]运算符进行索引访问

  • 确定一组向量是否线性无关

  • 确定两个矢量是否平行

  • 生成任意大小的恒等式矩阵的静态方法

  • 连接两个矩阵的静态方法

  • 打印时,浮点数显示为适当的分数

  • 相等测试会导致浮点错误

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java类。getResource和ClassLoader。getSystemResource:有没有理由选择其中一个而不是另一个?   在Java中以编程方式粘贴后恢复剪贴板   Java字符串到日期没有时间   JavaSpring注释:@Component起作用,@Repository不起作用   java“addScript”在HSQL中是否有最大记录计数?   java如何将值从JDialog框返回到父JFrame?   java我的模块库的用户有没有办法访问尚未导出的类?   java javac:未找到命令   java如何解决jsoup错误:无法找到请求目标的有效证书路径   类中的java作用域变量   Java中集合实现中的arraylist add()方法不起作用   java如何使用while循环和从用户接收输入来近似Pi?   java Spring安全CSRF培训模式   在安卓系统中,如何通过在警报框外单击来限制用户?