2020-09-30 08:38:00 +00:00
|
|
|
# Linear algebra library for Python
|
2018-10-19 12:48:28 +00:00
|
|
|
|
2020-09-30 08:38:00 +00:00
|
|
|
This module contains classes and functions for doing linear algebra.
|
2018-10-19 12:48:28 +00:00
|
|
|
|
|
|
|
---
|
|
|
|
|
2020-09-30 08:38:00 +00:00
|
|
|
## Overview
|
2018-10-19 12:48:28 +00:00
|
|
|
|
2020-09-30 08:38:00 +00:00
|
|
|
### class Vector
|
2019-10-07 18:32:16 +00:00
|
|
|
-
|
2020-09-30 08:38:00 +00:00
|
|
|
- This class represents a vector of arbitrary size and related operations.
|
|
|
|
|
2021-10-27 03:48:43 +00:00
|
|
|
**Overview of the methods:**
|
2020-09-30 08:38:00 +00:00
|
|
|
|
2021-10-27 03:48:43 +00:00
|
|
|
- constructor(components) : init the vector
|
|
|
|
- set(components) : changes the vector components.
|
2020-09-30 08:38:00 +00:00
|
|
|
- \_\_str\_\_() : toString method
|
2021-10-27 03:48:43 +00:00
|
|
|
- component(i): gets the i-th component (0-indexed)
|
2020-09-30 08:38:00 +00:00
|
|
|
- \_\_len\_\_() : gets the size / length of the vector (number of components)
|
2021-10-27 03:48:43 +00:00
|
|
|
- euclidean_length() : returns the eulidean length of the vector
|
2020-09-30 08:38:00 +00:00
|
|
|
- operator + : vector addition
|
|
|
|
- operator - : vector subtraction
|
|
|
|
- operator * : scalar multiplication and dot product
|
2021-10-27 03:48:43 +00:00
|
|
|
- copy() : copies this vector and returns it
|
|
|
|
- change_component(pos,value) : changes the specified component
|
2020-09-30 08:38:00 +00:00
|
|
|
|
2021-10-27 03:48:43 +00:00
|
|
|
- function zero_vector(dimension)
|
2020-09-30 08:38:00 +00:00
|
|
|
- returns a zero vector of 'dimension'
|
2021-10-27 03:48:43 +00:00
|
|
|
- function unit_basis_vector(dimension, pos)
|
|
|
|
- returns a unit basis vector with a one at index 'pos' (0-indexed)
|
|
|
|
- function axpy(scalar, vector1, vector2)
|
2020-09-30 08:38:00 +00:00
|
|
|
- computes the axpy operation
|
2021-10-27 03:48:43 +00:00
|
|
|
- function random_vector(N, a, b)
|
|
|
|
- returns a random vector of size N, with random integer components between 'a' and 'b' inclusive
|
2018-11-12 18:08:08 +00:00
|
|
|
|
2019-10-07 18:32:16 +00:00
|
|
|
### class Matrix
|
|
|
|
-
|
2018-10-19 12:48:28 +00:00
|
|
|
- This class represents a matrix of arbitrary size and operations on it.
|
|
|
|
|
2021-10-27 03:48:43 +00:00
|
|
|
**Overview of the methods:**
|
2020-09-30 08:38:00 +00:00
|
|
|
|
|
|
|
- \_\_str\_\_() : returns a string representation
|
|
|
|
- operator * : implements the matrix vector multiplication
|
|
|
|
implements the matrix-scalar multiplication.
|
2021-10-27 03:48:43 +00:00
|
|
|
- change_component(x, y, value) : changes the specified component.
|
|
|
|
- component(x, y) : returns the specified component.
|
2020-09-30 08:38:00 +00:00
|
|
|
- width() : returns the width of the matrix
|
2019-10-24 09:08:45 +00:00
|
|
|
- height() : returns the height of the matrix
|
2021-10-27 03:48:43 +00:00
|
|
|
- determinant() : returns the determinant of the matrix if it is square
|
2020-09-30 08:38:00 +00:00
|
|
|
- operator + : implements the matrix-addition.
|
2021-10-27 03:48:43 +00:00
|
|
|
- operator - : implements the matrix-subtraction
|
2020-09-30 08:38:00 +00:00
|
|
|
|
2021-10-27 03:48:43 +00:00
|
|
|
- function square_zero_matrix(N)
|
2020-09-30 08:38:00 +00:00
|
|
|
- returns a square zero-matrix of dimension NxN
|
2021-10-27 03:48:43 +00:00
|
|
|
- function random_matrix(W, H, a, b)
|
|
|
|
- returns a random matrix WxH with integer components between 'a' and 'b' inclusive
|
2018-10-19 12:48:28 +00:00
|
|
|
---
|
|
|
|
|
2020-09-30 08:38:00 +00:00
|
|
|
## Documentation
|
2018-10-19 12:48:28 +00:00
|
|
|
|
2019-11-23 03:06:52 +00:00
|
|
|
This module uses docstrings to enable the use of Python's in-built `help(...)` function.
|
2021-10-27 03:48:43 +00:00
|
|
|
For instance, try `help(Vector)`, `help(unit_basis_vector)`, and `help(CLASSNAME.METHODNAME)`.
|
2018-10-19 12:48:28 +00:00
|
|
|
|
|
|
|
---
|
|
|
|
|
2020-09-30 08:38:00 +00:00
|
|
|
## Usage
|
2018-10-19 12:48:28 +00:00
|
|
|
|
2019-11-23 03:06:52 +00:00
|
|
|
Import the module `lib.py` from the **src** directory into your project.
|
2020-09-30 08:38:00 +00:00
|
|
|
Alternatively, you can directly use the Python bytecode file `lib.pyc`.
|
2018-10-19 12:48:28 +00:00
|
|
|
|
|
|
|
---
|
|
|
|
|
2020-09-30 08:38:00 +00:00
|
|
|
## Tests
|
2018-10-19 12:48:28 +00:00
|
|
|
|
2019-11-23 03:06:52 +00:00
|
|
|
`src/tests.py` contains Python unit tests which can be run with `python3 -m unittest -v`.
|