pentapy.tools

The tools module of pentapy.

The following functions are provided

diag_indices(n[, offset])

Get indices for the main or minor diagonals of a matrix.

shift_banded(mat[, up, low, col_to_row, copy])

Shift rows of a banded matrix.

create_banded(mat[, up, low, col_wise, dtype])

Create a banded matrix from a given quadratic Matrix.

create_full(mat[, up, low, col_wise])

Create a (n x n) Matrix from a given banded matrix.

pentapy.tools.create_banded(mat, up=2, low=2, col_wise=True, dtype=None)[source]

Create a banded matrix from a given quadratic Matrix.

The Matrix will to be returned as a flattend matrix. Either in a column-wise flattend form:

[[0        0        Dup2[2]  ... Dup2[N-2]  Dup2[N-1]  Dup2[N] ]
 [0        Dup1[1]  Dup1[2]  ... Dup1[N-2]  Dup1[N-1]  Dup1[N] ]
 [Diag[0]  Diag[1]  Diag[2]  ... Diag[N-2]  Diag[N-1]  Diag[N] ]
 [Dlow1[0] Dlow1[1] Dlow1[2] ... Dlow1[N-2] Dlow1[N-1] 0       ]
 [Dlow2[0] Dlow2[1] Dlow2[2] ... Dlow2[N-2] 0          0       ]]

Then use:

col_wise=True

Or in a row-wise flattend form:

[[Dup2[0]  Dup2[1]  Dup2[2]  ... Dup2[N-2]  0          0       ]
 [Dup1[0]  Dup1[1]  Dup1[2]  ... Dup1[N-2]  Dup1[N-1]  0       ]
 [Diag[0]  Diag[1]  Diag[2]  ... Diag[N-2]  Diag[N-1]  Diag[N] ]
 [0        Dlow1[1] Dlow1[2] ... Dlow1[N-2] Dlow1[N-1] Dlow1[N]]
 [0        0        Dlow2[2] ... Dlow2[N-2] Dlow2[N-2] Dlow2[N]]]

Then use:

col_wise=False

Dup1 and Dup2 or the first and second upper minor-diagonals and Dlow1 resp. Dlow2 are the lower ones. The number of upper and lower minor-diagonals can be altered.

Parameters
  • mat (numpy.ndarray) – The full (n x n) Matrix.

  • up (int) – The number of upper minor-diagonals. Default: 2

  • low (int) – The number of lower minor-diagonals. Default: 2

  • col_wise (bool, optional) – Use column-wise storage. If False, use row-wise storage. Default: True

Returns

Bandend matrix

Return type

numpy.ndarray

pentapy.tools.create_full(mat, up=2, low=2, col_wise=True)[source]

Create a (n x n) Matrix from a given banded matrix.

The given Matrix has to be a flattend matrix. Either in a column-wise flattend form:

[[0        0        Dup2[2]  ... Dup2[N-2]  Dup2[N-1]  Dup2[N] ]
 [0        Dup1[1]  Dup1[2]  ... Dup1[N-2]  Dup1[N-1]  Dup1[N] ]
 [Diag[0]  Diag[1]  Diag[2]  ... Diag[N-2]  Diag[N-1]  Diag[N] ]
 [Dlow1[0] Dlow1[1] Dlow1[2] ... Dlow1[N-2] Dlow1[N-1] 0       ]
 [Dlow2[0] Dlow2[1] Dlow2[2] ... Dlow2[N-2] 0          0       ]]

Then use:

col_wise=True

Or in a row-wise flattend form:

[[Dup2[0]  Dup2[1]  Dup2[2]  ... Dup2[N-2]  0          0       ]
 [Dup1[0]  Dup1[1]  Dup1[2]  ... Dup1[N-2]  Dup1[N-1]  0       ]
 [Diag[0]  Diag[1]  Diag[2]  ... Diag[N-2]  Diag[N-1]  Diag[N] ]
 [0        Dlow1[1] Dlow1[2] ... Dlow1[N-2] Dlow1[N-1] Dlow1[N]]
 [0        0        Dlow2[2] ... Dlow2[N-2] Dlow2[N-2] Dlow2[N]]]

Then use:

col_wise=False

Dup1 and Dup2 or the first and second upper minor-diagonals and Dlow1 resp. Dlow2 are the lower ones. The number of upper and lower minor-diagonals can be altered.

Parameters
  • mat (numpy.ndarray) – The flattened Matrix.

  • up (int) – The number of upper minor-diagonals. Default: 2

  • low (int) – The number of lower minor-diagonals. Default: 2

  • col_wise (bool, optional) – Input is in column-wise storage. If False, use as row-wise storage. Default: True

Returns

Full matrix.

Return type

numpy.ndarray

pentapy.tools.diag_indices(n, offset=0)[source]

Get indices for the main or minor diagonals of a matrix.

This returns a tuple of indices that can be used to access the main diagonal of an array a with a.ndim == 2 dimensions and shape (n, n).

Parameters
  • n (int) – The size, along each dimension, of the arrays for which the returned indices can be used.

  • offset (int, optional) – The diagonal offset.

Returns

pentapy.tools.shift_banded(mat, up=2, low=2, col_to_row=True, copy=True)[source]

Shift rows of a banded matrix.

Either from column-wise to row-wise storage or vice versa.

The Matrix has to be given as a flattend matrix. Either in a column-wise flattend form:

[[0        0        Dup2[2]  ... Dup2[N-2]  Dup2[N-1]  Dup2[N] ]
 [0        Dup1[1]  Dup1[2]  ... Dup1[N-2]  Dup1[N-1]  Dup1[N] ]
 [Diag[0]  Diag[1]  Diag[2]  ... Diag[N-2]  Diag[N-1]  Diag[N] ]
 [Dlow1[0] Dlow1[1] Dlow1[2] ... Dlow1[N-2] Dlow1[N-1] 0       ]
 [Dlow2[0] Dlow2[1] Dlow2[2] ... Dlow2[N-2] 0          0       ]]

Then use:

col_to_row=True

Or in a row-wise flattend form:

[[Dup2[0]  Dup2[1]  Dup2[2]  ... Dup2[N-2]  0          0       ]
 [Dup1[0]  Dup1[1]  Dup1[2]  ... Dup1[N-2]  Dup1[N-1]  0       ]
 [Diag[0]  Diag[1]  Diag[2]  ... Diag[N-2]  Diag[N-1]  Diag[N] ]
 [0        Dlow1[1] Dlow1[2] ... Dlow1[N-2] Dlow1[N-1] Dlow1[N]]
 [0        0        Dlow2[2] ... Dlow2[N-2] Dlow2[N-2] Dlow2[N]]]

Then use:

col_to_row=False

Dup1 and Dup2 are the first and second upper minor-diagonals and Dlow1 resp. Dlow2 are the lower ones. The number of upper and lower minor-diagonals can be altered.

Parameters
  • mat (numpy.ndarray) – The Matrix or the flattened Version of the pentadiagonal matrix.

  • up (int) – The number of upper minor-diagonals. Default: 2

  • low (int) – The number of lower minor-diagonals. Default: 2

  • col_to_row (bool, optional) – Shift from column-wise to row-wise storage or vice versa. Default: True

  • copy (bool, optional) – Copy the input matrix or overwrite it. Default: True

Returns

Shifted bandend matrix

Return type

numpy.ndarray