mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-03-28 09:26:44 +00:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
ab246373e6
commit
d470987ca8
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user