m_n_kappa.matrices.Identity#

class m_n_kappa.matrices.Identity(row_column_number, diagonal_value=1.0)#

Bases: Matrix

Identity Matrix

New in version 0.2.0.

Where the diagonal values have a given value and all other values are zero.

Parameters:
  • row_column_number (int) – number of rows and columns of the matrix

  • diagonal_value (float) – value along the diagonal (Default: 1.0)

Methods

add(matrix)

add this matrix to another matrix

append(vector)

Appends the given vector as column-vector to this vector

column(number)

give the column with the given number

column_vector(column_number)

vector of the given column in the matrix

diagonal()

build new matrix inheriting the diagonal from this matrix and put all other places to zero

entry(row_number, column_number)

get the of the matrix at the given position

multiply_by(multiplicant)

multiplies this matrix with the given multiplicant

orthonormal_triangular([algorithm])

Determine orthogonal Matrix \(Q\) and (upper) triangular Matrix \(R\) of this matrix

replace(row, column, value)

row(number)

give the row with the given number

row_vector(row_number)

vector of the given row in the matrix

subtract(matrix)

subtracts the given matrix form this matrix

transpose()

transposes the matrix and gives a new matrix

Attributes

column_number

gives number of columns of the matrix

matrix

shows the matrix in list-form

row_number

gives the number of rows of the matrix

add(matrix)#

add this matrix to another matrix

Parameters:

matrix (Matrix) – the Matrix this matrix is added to

Returns:

new Matrix where each entry is added to the corresponding one in the other matrix

Return type:

Matrix

Raises:

TypeError – if matrix is not of type m_n_kappa.matrices.Matrix

Examples

>>> from m_n_kappa.matrices import Matrix
>>> this_matrix = Matrix([[1, -3, 2], [1, 2, 7]])
>>> other_matrix = Matrix([[0, 3, 5], [2, 1, -1]])
>>> this_matrix.add(other_matrix)
Matrix([[1.0, 0.0, 7.0], [3.0, 3.0, 6.0]])
append(vector)#

Appends the given vector as column-vector to this vector

Parameters:

vector (Vector) – column-vector to append to this matrix

Returns:

this matrix with appended vector as additional column-vector

Return type:

Matrix

column(number)#

give the column with the given number

Parameters:

number (int) – number of the needed column

Returns:

values of the given column in a list from top to bottom

Return type:

list

column_vector(column_number)#

vector of the given column in the matrix

Parameters:

column_number (int) – number of the column

Returns:

vector of the column given by the number

Return type:

Vector

diagonal()#

build new matrix inheriting the diagonal from this matrix and put all other places to zero

entry(row_number, column_number)#

get the of the matrix at the given position

Parameters:
  • row_number (int) – number of row where the entry is located

  • column_number (int) – number of the columne where the entry is located

Returns:

value given at the desired position

Return type:

float

Examples

>>> from m_n_kappa.matrices import Matrix
>>> a_matrix = Matrix([[0, 1, 2], [3, 4, 5]])
>>> a_matrix.entry(1, 1)
4.0
multiply_by(multiplicant)#

multiplies this matrix with the given multiplicant

assumes that this matrix is on the left and the multiplicant is on the right of the multiplication-sign

Parameters:

multiplicant (Matrix | Vector | float) – Multiplicant to multiply this matrix with

Returns:

depending on the input the multiplication results in Matrix or a Vector

Return type:

Matrix | Vector

Raises:

ValueError – in case multiplicant is either of type Matrix, nor Matrix nor float

Examples

>>> from m_n_kappa.matrices import Matrix
>>> this_matrix = Matrix([[3, 2, 1], [1, 0, 2]])

Multiply another Matrix:

>>> other_matrix = Matrix([[1, 2], [0, 1], [4, 0]])
>>> this_matrix.multiply_by(other_matrix)
Matrix([[7.0, 8.0], [9.0, 2.0]])

Multiply a vector:

>>> a_vector = Vector([1, 2, 3])
>>> this_matrix.multiply_by(a_vector)
Vector([1.0, 26.0])

Multiply a number (=scalar):

>>> this_matrix.multiply_by(5)
Matrix([[5.0, -15.0, 10.0], [5.0, 10.0, 35.0]])
orthonormal_triangular(algorithm='Givens-rotation')#

Determine orthogonal Matrix \(Q\) and (upper) triangular Matrix \(R\) of this matrix

Parameters:

algorithm (str) –

Algorithm for computation of \(Q\) and \(R\). Currently following algorithms are supported:

Returns:

First entry is the orthogonal matrix of this matrix. Second entry is the (upper) triangluar Matrix of this matrix.

Return type:

tuple[Matrix, Matrix]

row(number)#

give the row with the given number

Parameters:

number (int) – number of the needed row

Returns:

values of the needed row

Return type:

list

row_vector(row_number)#

vector of the given row in the matrix

Parameters:

row_number (int) – number of the row

Returns:

vector of the row given by the number

Return type:

Vector

subtract(matrix)#

subtracts the given matrix form this matrix

Parameters:

matrix (Matrix) – matrix that is subtracted from this one

Returns:

New Matrix where each value of the given matrix is subtracted from this one

Return type:

Matrix

Examples

>>> from m_n_kappa.matrices import Matrix
>>> this_matrix = Matrix([[1, -3, 2], [1, 2, 7]])
>>> other_matrix = Matrix([[0, 3, 5], [2, 1, -1]])
>>> this_matrix.subtract(other_matrix)
Matrix([[1.0, -6.0, -3.0], [-1.0, 1.0, 8.0]])
transpose()#

transposes the matrix and gives a new matrix

Examples

>>> from m_n_kappa.matrices import Matrix
>>> a_matrix = Matrix([[0, 1, 2], [3, 4, 5]])
>>> a_matrix.transpose()
Matrix([[0.0, 3.0], [1.0, 4.0], [2.0, 5.0]])
property column_number: int#

gives number of columns of the matrix

property matrix: list[list]#

shows the matrix in list-form

property row_number: int#

gives the number of rows of the matrix