Skip to content

Commit d470987

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent ab24637 commit d470987

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

linear_algebra/Lanczos-algorithm.py

+15-13
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
import numpy as np
2+
3+
24
def lanczos(A: np.ndarray) -> ([float], [float]):
35
"""
4-
Implements the Lanczos algorithm for a symmetric matrix.
6+
Implements the Lanczos algorithm for a symmetric matrix.
57
6-
Parameters:
7-
-----------
8-
matrix : numpy.ndarray
9-
Symmetric matrix of size (n, n).
8+
Parameters:
9+
-----------
10+
matrix : numpy.ndarray
11+
Symmetric matrix of size (n, n).
1012
11-
Returns:
12-
--------
13-
alpha : [float]
14-
List of diagonal elements of the resulting tridiagonal matrix.
15-
beta : [float]
16-
List of off-diagonal elements of the resulting tridiagonal matrix.
17-
"""
13+
Returns:
14+
--------
15+
alpha : [float]
16+
List of diagonal elements of the resulting tridiagonal matrix.
17+
beta : [float]
18+
List of off-diagonal elements of the resulting tridiagonal matrix.
19+
"""
1820
n = A.shape[0]
1921
V = np.zeros((n, n))
2022
V[:, 0] = np.random.randn(n)
@@ -31,4 +33,4 @@ def lanczos(A: np.ndarray) -> ([float], [float]):
3133
w -= beta[j - 1] * V[:, j - 1]
3234
beta.append(np.linalg.norm(w))
3335
V[:, j + 1] = w / beta[j]
34-
return alpha, beta
36+
return alpha, beta

0 commit comments

Comments
 (0)