mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-27 15:01:08 +00:00
Changed the structure to correspond with PEP8 convention.
This commit is contained in:
parent
baf934f4df
commit
d2afa4cc8b
|
@ -1,4 +1,6 @@
|
|||
import numpy as np
|
||||
|
||||
|
||||
def lanczos(a: np.ndarray) -> tuple[list[float], list[float]]:
|
||||
"""
|
||||
Implements the Lanczos algorithm for a symmetric matrix.
|
||||
|
@ -20,8 +22,8 @@ def lanczos(a: np.ndarray) -> tuple[list[float], list[float]]:
|
|||
rng = np.random.default_rng()
|
||||
v[:, 0] = rng.standard_normal(n)
|
||||
v[:, 0] /= np.linalg.norm(v[:, 0])
|
||||
alpha : list[float] = []
|
||||
beta : list[float] = []
|
||||
alpha: list[float] = []
|
||||
beta: list[float] = []
|
||||
for j in range(n):
|
||||
w = np.dot(a, v[:, j])
|
||||
alpha.append(np.dot(w, v[:, j]))
|
||||
|
@ -32,4 +34,4 @@ def lanczos(a: np.ndarray) -> tuple[list[float], list[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…
Reference in New Issue
Block a user