From d470987ca8b417e435cc6f4d2f4fd2a2351e2fd5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 20 Nov 2024 09:16:12 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- linear_algebra/Lanczos-algorithm.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/linear_algebra/Lanczos-algorithm.py b/linear_algebra/Lanczos-algorithm.py index 4bdba1bce..d8e9ea291 100644 --- a/linear_algebra/Lanczos-algorithm.py +++ b/linear_algebra/Lanczos-algorithm.py @@ -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 \ No newline at end of file + return alpha, beta