pyUni10.Matrix¶
-
class
pyUni10.
Matrix
¶ Proxy of C++ uni10::Matrix class
Class for matrices
-
pyUni10.
Matrix
(Rnum, Cnum, [elem, ]diag=False)
-
pyUni10.
Matrix
(Ma) Creates a Real Matrix object
Parameters: - Rnum (int) – number of Rows
- Cnum (int) – number of Columns
- diag (bool) – Set True for a diagonal matrix
- elem (iterable) – Matrix elements
- Ma (Matrix) – another Matrix object
Returns: a Matrix object
Return type:
-
pyUni10.
CMatrix
(Rnum, Cnum, [elem, ]diag=False)¶ Creates a Complex Matrix object
Parameters: - Rnum (int) – number of Rows
- Cnum (int) – number of Columns
- diag (bool) – Set True for a diagonal matrix
- elem (iterable) – Matrix elements
- Ma (Matrix) – another Matrix object
Returns: a Complex Matrix object
Return type: Methods
If no datatype flag is specified, the member functions default to Real. To explicitly declare the data type, the class provides constructors and member functions with the following syntax:
func(RTYPE, ...)
for Real datatype andfunc(CTYPE), ...)
for Complex datatype.-
Matrix.
col
()¶ Returns the number of columns in Matrix
Returns: number of columns in Matrix Return type: int
-
Matrix.
eigh
()¶ - Diagonalizes a symmetric/hermitian Matrix and returns a tuple of matrices (\(D, U\)),
where \(D\) is a diagonal matrix of eigenvalues and \(U\) is a matrix of row-vectors of eigenvectors.
return: - \(D\) : diagonal matrix of eigenvalues
- \(U\) : matrix of eigenvectors
rtype: tuple of Matrix
Note
This function will not check wether the matrix is symmetric/hermitian.
The operation is a wrapper of Lapack function
dsyev()
for Real matrixzheev()
for Complex matrix.
-
Matrix.
eig
()¶ Diagonalizes a general Matrix and returns a tuple of matrices (\(D, U\)), where \(D\) is a diagonal matrix of eigenvalues and \(U\) is a matrix of row-vectors of right eigenvectors.
Returns: - \(D\) : diagonal matrix of eigenvalues
- \(U\) : matrix of right eigenvectors
Return type: tuple of Matrix
Note
Only the right eigenvectors will be given. The operation is a wrapper of Lapack function
Xsyev()
.-
Matrix.
elemNum
()¶ Returns the number of elements in Matrix
Returns: number of elements in Matrix Return type: int
-
Matrix.
getElem
()¶ Returns the reference to the elements of Matrix
Returns: reference to the element of Matrix Return type: float *
-
Matrix.
isDiag
()¶ Checks whether Matrix is diagonal
Returns: True or False Return type: bool
-
Matrix.
inverse
()¶ Returns inverse matrix of Matrix
Returns: inverse matrix of Matrix Rtpye: Matrix
-
Matrix.
load
(filename)¶ Loads Matrix from a binary file named filename
Parameters: filename (str) – input filename
-
Matrix.
norm
()¶ Returns \(L^2\) norm of Matrix
Returns: \(L^2\) norm of Matrix Return type: float
-
Matrix.
orthoRand
()¶ Generates an orthogonal basis with random elements and assigns it to the elements of Matrix
Returns: Matrix of orthogonal basis Return type: Matrix
-
Matrix.
randomize
()¶ Assigns random elements to Matrix
Returns: Matrix of random elements Return type: Matrix
-
Matrix.
resize
(Rnum, Cnum)¶ Set the dimensions of Matrix to (Rnum, Cnum)
Returns: Matrix of size (Rnum, Cnum) Return type: Matrix
-
Matrix.
row
()¶ Returns the number of rows in Matrix
Returns: number of rows in Matrix Return type: int
-
Matrix.
save
(filename)¶ Saves Matrix to a binary file named filename
Parameters: filename (str) – output filename
-
Matrix.
setElem
(elem)¶ Set elements of Matrix to elem
Parameters: elem (array of floats) – data
-
Matrix.
set_zero
()¶ Set elements of Matrix to zero
Parameters: elem (array of floats) – data
-
Matrix.
sum
()¶ Performs the summation of all elements in Matrix
Returns: sum of all elements in Matrix Return type: float
-
Matrix.
svd
()¶ Performs SVD of Matrix
Factorizes the \(m \times n\) matrix \(A\) into two unitary matrices \(U\) and \(V^\dagger\), and a diagonal matrix \(\Sigma\) of singular values (real, non-negative) such that
\[A= U \Sigma V^{\dagger}\]Returns: - \(U\) : a \(m \times n\) row-major matrix
- \(\Sigma\) : a \(n \times n\) diagonal matrix
- \(V^{\dagger}\): a \(n \times m\) row-major matrix
Return type: tuple of Matix Note
This is a wrapper of the Lapack function
Xgesvd()
-
Matrix.
trace
()¶ Takes the trace of a square matrix Matrix
Returns: trace of a square matrix Matrix Return type: float Raise: RunTimeError if Matrix is not a square matrix
-
Matrix.
transpose
()¶ Performs in-place transpose of a Real Matrix. The number of rows and the number of columns are exchanged.
Returns: Matrix Return type: Matrix
-
Matrix.
conj
()¶ Performs in-place complex conjugation of elements in Matrix.
Returns: complex conjugate of Matrix Return type: Matrix
-
Matrix.
cTranspose
()¶ Performs in-place Hermitian conjugate of a Complex Matrix. The number of rows and the number of columns are exchanged.
Returns: Matrix Return type: Matrix
-
Matrix.
max
()¶ Returns the maximum matrix element
Returns: maximum matrix elements Return type: float
-
Matrix.
absMax
()¶ Returns the matrix element with the maximum absolute value
Returns: the matrix element with the maximum absolute value Return type: float Note
This method only works for Real matrix
-
Matrix.
absMaxNorm
()¶ Normalizes the Matrix such that the maximum matrix element has absolute value 1
Returns: normalized Matrix Return type: Matrix Note
This method only works for Real matrix
-
Matrix.
qr
()¶
-
Matrix.
rq
()¶
-
Matrix.
ql
()¶
-
Matrix.
lq
()¶ Performs QR, RQ, QL, LQ decompositions of Matrix.
Returns: A tuple of Matrix of upper(R)/lower(L) triangular matrix and a unitary matrix (Q) Return type: tuple of Matrix
-
Matrix.
typeID
()¶ Returns datatype of Matrix
Returns: CTYPE or RTYPE Return type: int