Matrix
Matrix
Matrix()A matrix with rational polynomial coefficients.
Methods
| Name | Description |
|---|---|
__add__ |
Add two matrices self and rhs, returning the result. |
__copy__ |
Copy the matrix. |
__eq__ |
Compare two matrices. |
__getitem__ |
Get the entry at position key in the matrix. |
__matmul__ |
Matrix multiply self and rhs, returning the result. |
__mul__ |
Matrix multiply self and rhs, returning the result. |
__neg__ |
Negate the matrix, returning the result. |
__neq__ |
Compare two matrices. |
__new__ |
Create a new zeroed matrix with nrows rows and ncols columns. |
__rmatmul__ |
Matrix multiply rhs and self, returning the result. |
__rmul__ |
Matrix multiply rhs and self, returning the result. |
__str__ |
Print the matrix in a human-readable format. |
__sub__ |
Subtract matrix rhs from self, returning the result. |
__truediv__ |
Divide this matrix by scalar rhs and return the result. |
augment |
Augment the matrix with another matrix, e.g |
content |
Get the content, i.e., the GCD of the coefficients. |
det |
Return the determinant of the matrix. |
eye |
Create a new matrix with the scalars diag on the main diagonal and zeroes elsewhere. |
format |
Convert the matrix into a human-readable string, with tunable settings. |
from_linear |
Create a new matrix from a 1-dimensional vector of scalars. |
from_nested |
Create a new matrix from a 2-dimensional vector of scalars. |
identity |
Create a new square matrix with nrows rows and ones on the main diagonal and zeroes elsewhere. |
inv |
Return the inverse of the matrix, if it exists. |
is_diagonal |
Return true iff every non- main diagonal entry in the matrix is zero. |
is_zero |
Return true iff every entry in the matrix is zero. |
map |
Apply a function f to every entry of the matrix. |
ncols |
Get the number of columns in the matrix. |
nrows |
Get the number of rows in the matrix. |
primitive_part |
Construct the same matrix, but with the content removed. |
row_reduce |
Row-reduce the first max_col columns of the matrix in-place using Gaussian elimination and return the rank. |
solve |
Solve A * x = b for x, where A is the current matrix. |
solve_any |
Solve A * x = b for x, where A is the current matrix and return any solution if the system is underdetermined. |
split_col |
Split the matrix into two matrices at column col. |
swap_cols |
Swap columns i and j of the matrix in-place. |
swap_rows |
Swap rows i and j of the matrix in-place, starting from column start. |
to_latex |
Convert the matrix into a LaTeX string. |
transpose |
Return the transpose of the matrix. |
vec |
Create a new column vector from a list of scalars. |
__add__
Matrix.__add__(rhs: Matrix) -> MatrixAdd two matrices self and rhs, returning the result.
__copy__
Matrix.__copy__() -> MatrixCopy the matrix.
__eq__
Matrix.__eq__(other: Matrix) -> boolCompare two matrices.
__getitem__
Matrix.__getitem__(key: Tuple[int, int]) -> RationalPolynomialGet the entry at position key in the matrix.
__matmul__
Matrix.__matmul__(rhs: Matrix | RationalPolynomial | Polynomial | Expression | int) -> MatrixMatrix multiply self and rhs, returning the result.
__mul__
Matrix.__mul__(rhs: Matrix | RationalPolynomial | Polynomial | Expression | int) -> MatrixMatrix multiply self and rhs, returning the result.
__neg__
Matrix.__neg__() -> MatrixNegate the matrix, returning the result.
__neq__
Matrix.__neq__(other: Matrix) -> boolCompare two matrices.
__new__
Matrix.__new__(nrows: int, ncols: int) -> MatrixCreate a new zeroed matrix with nrows rows and ncols columns.
__rmatmul__
Matrix.__rmatmul__(rhs: RationalPolynomial | Polynomial | Expression | int) -> MatrixMatrix multiply rhs and self, returning the result.
__rmul__
Matrix.__rmul__(rhs: RationalPolynomial | Polynomial | Expression | int) -> MatrixMatrix multiply rhs and self, returning the result.
__str__
Matrix.__str__() -> strPrint the matrix in a human-readable format.
__sub__
Matrix.__sub__(rhs: Matrix) -> MatrixSubtract matrix rhs from self, returning the result.
__truediv__
Matrix.__truediv__(rhs: RationalPolynomial | Polynomial | Expression | int) -> MatrixDivide this matrix by scalar rhs and return the result.
augment
Matrix.augment(b: Matrix) -> MatrixAugment the matrix with another matrix, e.g. create [A B] from matrix A and B.
Returns an error when the matrices do not have the same number of rows.
content
Matrix.content() -> RationalPolynomialGet the content, i.e., the GCD of the coefficients.
det
Matrix.det() -> RationalPolynomialReturn the determinant of the matrix.
eye
Matrix.eye(diag: Sequence[RationalPolynomial | Polynomial | Expression | int]) -> MatrixCreate a new matrix with the scalars diag on the main diagonal and zeroes elsewhere.
format
Matrix.format(
mode: PrintMode = PrintMode.Symbolica,
max_line_length: int | None = 80,
indentation: int = 4,
fill_indented_lines: bool = True,
pretty_matrix = True,
number_thousands_separator: Optional[str] = None,
multiplication_operator: str = '*',
double_star_for_exponentiation: bool = False,
square_brackets_for_function: bool = False,
function_brackets: tuple[str, str] = ('(', ')'),
num_exp_as_superscript: bool = True,
precision: Optional[int] = None,
show_namespaces: bool = False,
hide_namespace: Optional[str] = None,
include_attributes: bool = False,
max_terms: Optional[int] = None,
custom_print_mode: Optional[int] = None,
) -> strConvert the matrix into a human-readable string, with tunable settings.
from_linear
Matrix.from_linear(
nrows: int,
ncols: int,
entries: Sequence[RationalPolynomial | Polynomial | Expression | int],
) -> MatrixCreate a new matrix from a 1-dimensional vector of scalars.
from_nested
Matrix.from_nested(entries: Sequence[Sequence[RationalPolynomial | Polynomial | Expression | int]]) -> MatrixCreate a new matrix from a 2-dimensional vector of scalars.
identity
Matrix.identity(nrows: int) -> MatrixCreate a new square matrix with nrows rows and ones on the main diagonal and zeroes elsewhere.
inv
Matrix.inv() -> MatrixReturn the inverse of the matrix, if it exists.
is_diagonal
Matrix.is_diagonal() -> boolReturn true iff every non- main diagonal entry in the matrix is zero.
is_zero
Matrix.is_zero() -> boolReturn true iff every entry in the matrix is zero.
map
Matrix.map(f: Callable[[RationalPolynomial], RationalPolynomial]) -> MatrixApply a function f to every entry of the matrix.
ncols
Matrix.ncols() -> intGet the number of columns in the matrix.
nrows
Matrix.nrows() -> intGet the number of rows in the matrix.
primitive_part
Matrix.primitive_part() -> MatrixConstruct the same matrix, but with the content removed.
row_reduce
Matrix.row_reduce(max_col: int) -> intRow-reduce the first max_col columns of the matrix in-place using Gaussian elimination and return the rank.
solve
Matrix.solve(b: Matrix) -> MatrixSolve A * x = b for x, where A is the current matrix.
solve_any
Matrix.solve_any(b: Matrix) -> MatrixSolve A * x = b for x, where A is the current matrix and return any solution if the system is underdetermined.
split_col
Matrix.split_col(col: int) -> Tuple[Matrix, Matrix]Split the matrix into two matrices at column col.
swap_cols
Matrix.swap_cols(i: int, j: int) -> NoneSwap columns i and j of the matrix in-place.
swap_rows
Matrix.swap_rows(i: int, j: int, start: int = 0) -> NoneSwap rows i and j of the matrix in-place, starting from column start.
to_latex
Matrix.to_latex() -> strConvert the matrix into a LaTeX string.
transpose
Matrix.transpose() -> MatrixReturn the transpose of the matrix.
vec
Matrix.vec(entries: Sequence[RationalPolynomial | Polynomial | Expression | int]) -> MatrixCreate a new column vector from a list of scalars.