pycauset.DiagonalMatrix
A square matrix with non-zero entries only on the diagonal.
Construction
Use the factory, which takes a 1D vector of diagonal entries or a 2D square matrix:
import pycauset as pc
D = pc.diagonal([1.0, 2.0, 3.0]) # -> pycauset.DiagonalMatrix
D = pc.diagonal([ [1.0, 0.0], [0.0, 2.0] ]) # extracts the diagonal
The raw native constructor allocates an empty matrix, filled via set_diagonal:
A dense matrix can also be marked diagonal through the properties system:
Indexing
- Read:
x = D[i, j](zero wheni != j). - Write:
D[i, j] = value(off-diagonal writes are ignored for a diagonal matrix).
Methods
set_diagonal(i, value): set the i-th diagonal entry.get_diagonal(i): read the i-th diagonal entry.
Notes
DiagonalMatrix is recognized by the structure resolver as "diagonal", which enables
closed-form shortcuts for trace, determinant, matrix_rank, and norm.