numeric — replace the numeric module of CodeSkulptor
numeric module.
Replace the numeric module of CodeSkulptor.
Piece of SimpleGUICS2Pygame. https://bitbucket.org/OPiMedia/simpleguics2pygame
- license
GPLv3 — Copyright (C) 2013-2014, 2020-2021 Olivier Pirson
- author
Olivier Pirson — http://www.opimedia.be/
- version
May 5, 2021
- class SimpleGUICS2Pygame.numeric.Matrix(data: Sequence[Sequence[Union[int, float]]], _copy: bool = True)[source]
Matrix (m x n).
See http://en.wikipedia.org/wiki/Matrix_%28mathematics%29 .
- __add__(other: Matrix) Matrix [source]
To a matrix (m x n) return the matrix plus other.
- Parameters
other – Matrix (m x n)
- Returns
Matrix (m x n)
- __getitem__(i_j: Sequence[int]) float [source]
Return the value of the (m x n) matrix at row i and column j.
- Parameters
i_j – (0 <= int < m, 0 <= int < n) or [0 <= int < m, 0 <= int < n]
- Returns
float
- __init__(data: Sequence[Sequence[Union[int, float]]], _copy: bool = True) None [source]
Create a matrix with the 2-dimensional data.
If not _copy then data is directly used without copy. In this case, data must be a correct list of list of float. (Option not available in SimpleGUI of CodeSkulptor.)
- Parameters
data – (not empty tuple or list) of (same size tuple or list) of (int or float)
_copy – bool
- __mul__(other: Matrix) Matrix [source]
To a matrix (m x k) return the matrix multiply by other.
- Parameters
other – Matrix (k x n)
- Returns
Matrix (m x n)
- __setitem__(i_j: Sequence[int], value: Union[int, float]) None [source]
Change the value of the element at row i and column j, to the (m x n) matrix.
- Parameters
i_j – (0 <= int < m, 0 <= int < n) or [0 <= int < m, 0 <= int < n]
value – int or float
- __sub__(other: Matrix) Matrix [source]
To a matrix (m x n) return the matrix minus other.
- Parameters
other – Matrix (m x n)
- Returns
Matrix (m x n)
- __weakref__
list of weak references to the object (if defined)
- _is_identity(epsilon: Union[int, float] = 2.220446049250313e-16) bool [source]
If the matrix is an identity matrix then return True, else return False.
(Not available in SimpleGUI of CodeSkulptor.)
- Parameters
epsilon – 0 <= (float or int) < 1
- Returns
bool
- _is_zero(epsilon: Union[int, float] = 2.220446049250313e-16) bool [source]
If the matrix is a zeros matrix then return True, else return False.
(Not available in SimpleGUI of CodeSkulptor.)
- Parameters
epsilon – 0 <= (float or int) < 1
- Returns
bool
- _nb_columns() int [source]
Return n for a (m x n) matrix.
(Not available in SimpleGUI of CodeSkulptor.)
- Returns
int >= 1
- _nb_lines() int [source]
Return m to a (m x n) matrix.
(Not available in SimpleGUI of CodeSkulptor.)
- Returns
int >= 1
- abs() Matrix [source]
To a matrix (m x n) return the matrix with each element is the absolute value.
- Returns
Matrix (m x n)
- getcol(j: int) Matrix [source]
Return the (1 x m) matrix that is a copy of column j of the (m x n) matrix.
- Parameters
j – 0 <= int < n
- Returns
Matrix (1 x m)
- getrow(i: int) Matrix [source]
Return the (1 x n) matrix that is a copy of row i of the (m x n) matrix.
- Parameters
i – 0 <= int < m
- Returns
Matrix (1 x n)
- inverse(_epsilon: Union[int, float] = 2.220446049250313e-16) Matrix [source]
If the square matrix (n x n) is inversible then return the inverse, else raise an ValueError exception.
Algorithm used: Gaussian elimination. See http://en.wikipedia.org/wiki/Gaussian_elimination .
- Parameters
_epsilon – 0 <= (float or int) < 1 (Option not available in SimpleGUI of CodeSkulptor.)
- Returns
Matrix (n x n)
- Raise
ValueError if the matrix is not inversible
- SimpleGUICS2Pygame.numeric._EPSILON = 2.220446049250313e-16
The default epsilon value.
- SimpleGUICS2Pygame.numeric._zero(m: int, n: int) SimpleGUICS2Pygame.numeric.Matrix [source]
Return a (m x n) zeros matrix.
- Parameters
m – int >= 1
n – int >= 1
- Returns
Matrix (m x n)
- SimpleGUICS2Pygame.numeric.identity(size: int) SimpleGUICS2Pygame.numeric.Matrix [source]
Return a (size x size) identity matrix.
- Parameters
size – int >= 1
- Returns
Matrix (size x size)
[source]