[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot] 2024-11-20 09:16:12 +00:00
parent ab246373e6
commit d470987ca8

View File

@ -1,20 +1,22 @@
import numpy as np
def lanczos(A: np.ndarray) -> ([float], [float]):
"""
Implements the Lanczos algorithm for a symmetric matrix.
Implements the Lanczos algorithm for a symmetric matrix.
Parameters:
-----------
matrix : numpy.ndarray
Symmetric matrix of size (n, n).
Parameters:
-----------
matrix : numpy.ndarray
Symmetric matrix of size (n, n).
Returns:
--------
alpha : [float]
List of diagonal elements of the resulting tridiagonal matrix.
beta : [float]
List of off-diagonal elements of the resulting tridiagonal matrix.
"""
Returns:
--------
alpha : [float]
List of diagonal elements of the resulting tridiagonal matrix.
beta : [float]
List of off-diagonal elements of the resulting tridiagonal matrix.
"""
n = A.shape[0]
V = np.zeros((n, n))
V[:, 0] = np.random.randn(n)
@ -31,4 +33,4 @@ def lanczos(A: np.ndarray) -> ([float], [float]):
w -= beta[j - 1] * V[:, j - 1]
beta.append(np.linalg.norm(w))
V[:, j + 1] = w / beta[j]
return alpha, beta
return alpha, beta