matrix.matrix_class =================== .. py:module:: matrix.matrix_class Classes ------- .. autoapisummary:: matrix.matrix_class.Matrix Module Contents --------------- .. py:class:: Matrix(rows: list[list[int]]) Matrix object generated from a 2D array where each element is an array representing a row. Rows can contain type int or float. Common operations and information available. >>> rows = [ ... [1, 2, 3], ... [4, 5, 6], ... [7, 8, 9] ... ] >>> matrix = Matrix(rows) >>> print(matrix) [[1. 2. 3.] [4. 5. 6.] [7. 8. 9.]] Matrix rows and columns are available as 2D arrays >>> matrix.rows [[1, 2, 3], [4, 5, 6], [7, 8, 9]] >>> matrix.columns() [[1, 4, 7], [2, 5, 8], [3, 6, 9]] Order is returned as a tuple >>> matrix.order (3, 3) Squareness and invertability are represented as bool >>> matrix.is_square True >>> matrix.is_invertable() False Identity, Minors, Cofactors and Adjugate are returned as Matrices. Inverse can be a Matrix or Nonetype >>> print(matrix.identity()) [[1. 0. 0.] [0. 1. 0.] [0. 0. 1.]] >>> print(matrix.minors()) [[-3. -6. -3.] [-6. -12. -6.] [-3. -6. -3.]] >>> print(matrix.cofactors()) [[-3. 6. -3.] [6. -12. 6.] [-3. 6. -3.]] >>> # won't be apparent due to the nature of the cofactor matrix >>> print(matrix.adjugate()) [[-3. 6. -3.] [6. -12. 6.] [-3. 6. -3.]] >>> matrix.inverse() Traceback (most recent call last): ... TypeError: Only matrices with a non-zero determinant have an inverse Determinant is an int, float, or Nonetype >>> matrix.determinant() 0 Negation, scalar multiplication, addition, subtraction, multiplication and exponentiation are available and all return a Matrix >>> print(-matrix) [[-1. -2. -3.] [-4. -5. -6.] [-7. -8. -9.]] >>> matrix2 = matrix * 3 >>> print(matrix2) [[3. 6. 9.] [12. 15. 18.] [21. 24. 27.]] >>> print(matrix + matrix2) [[4. 8. 12.] [16. 20. 24.] [28. 32. 36.]] >>> print(matrix - matrix2) [[-2. -4. -6.] [-8. -10. -12.] [-14. -16. -18.]] >>> print(matrix ** 3) [[468. 576. 684.] [1062. 1305. 1548.] [1656. 2034. 2412.]] Matrices can also be modified >>> matrix.add_row([10, 11, 12]) >>> print(matrix) [[1. 2. 3.] [4. 5. 6.] [7. 8. 9.] [10. 11. 12.]] >>> matrix2.add_column([8, 16, 32]) >>> print(matrix2) [[3. 6. 9. 8.] [12. 15. 18. 16.] [21. 24. 27. 32.]] >>> print(matrix * matrix2) [[90. 108. 126. 136.] [198. 243. 288. 304.] [306. 378. 450. 472.] [414. 513. 612. 640.]] .. py:method:: __add__(other: Matrix) -> Matrix .. py:method:: __eq__(other: object) -> bool .. py:method:: __mul__(other: Matrix | float) -> Matrix .. py:method:: __ne__(other: object) -> bool .. py:method:: __neg__() -> Matrix .. py:method:: __pow__(other: int) -> Matrix .. py:method:: __repr__() -> str .. py:method:: __str__() -> str .. py:method:: __sub__(other: Matrix) -> Matrix .. py:method:: add_column(column: list[int], position: int | None = None) -> None .. py:method:: add_row(row: list[int], position: int | None = None) -> None .. py:method:: adjugate() -> Matrix .. py:method:: cofactors() -> Matrix .. py:method:: columns() -> list[list[int]] .. py:method:: determinant() -> int .. py:method:: dot_product(row: list[int], column: list[int]) -> int :classmethod: .. py:method:: get_cofactor(row: int, column: int) -> int .. py:method:: get_minor(row: int, column: int) -> int .. py:method:: identity() -> Matrix .. py:method:: inverse() -> Matrix .. py:method:: is_invertable() -> bool .. py:method:: minors() -> Matrix .. py:property:: is_square :type: bool .. py:property:: num_columns :type: int .. py:property:: num_rows :type: int .. py:property:: order :type: tuple[int, int]