mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-06 10:31:29 +08:00
fix mypy annotations for arithmetic_analysis (#6040)
* fixed mypy annotations for arithmetic_analysis * shortened numpy references
This commit is contained in:
@ -5,9 +5,13 @@ Gaussian elimination - https://en.wikipedia.org/wiki/Gaussian_elimination
|
||||
|
||||
|
||||
import numpy as np
|
||||
from numpy import float64
|
||||
from numpy.typing import NDArray
|
||||
|
||||
|
||||
def retroactive_resolution(coefficients: np.matrix, vector: np.ndarray) -> np.ndarray:
|
||||
def retroactive_resolution(
|
||||
coefficients: NDArray[float64], vector: NDArray[float64]
|
||||
) -> NDArray[float64]:
|
||||
"""
|
||||
This function performs a retroactive linear system resolution
|
||||
for triangular matrix
|
||||
@ -27,7 +31,7 @@ def retroactive_resolution(coefficients: np.matrix, vector: np.ndarray) -> np.nd
|
||||
|
||||
rows, columns = np.shape(coefficients)
|
||||
|
||||
x = np.zeros((rows, 1), dtype=float)
|
||||
x: NDArray[float64] = np.zeros((rows, 1), dtype=float)
|
||||
for row in reversed(range(rows)):
|
||||
sum = 0
|
||||
for col in range(row + 1, columns):
|
||||
@ -38,7 +42,9 @@ def retroactive_resolution(coefficients: np.matrix, vector: np.ndarray) -> np.nd
|
||||
return x
|
||||
|
||||
|
||||
def gaussian_elimination(coefficients: np.matrix, vector: np.ndarray) -> np.ndarray:
|
||||
def gaussian_elimination(
|
||||
coefficients: NDArray[float64], vector: NDArray[float64]
|
||||
) -> NDArray[float64]:
|
||||
"""
|
||||
This function performs Gaussian elimination method
|
||||
|
||||
@ -60,7 +66,7 @@ def gaussian_elimination(coefficients: np.matrix, vector: np.ndarray) -> np.ndar
|
||||
return np.array((), dtype=float)
|
||||
|
||||
# augmented matrix
|
||||
augmented_mat = np.concatenate((coefficients, vector), axis=1)
|
||||
augmented_mat: NDArray[float64] = np.concatenate((coefficients, vector), axis=1)
|
||||
augmented_mat = augmented_mat.astype("float64")
|
||||
|
||||
# scale the matrix leaving it triangular
|
||||
|
Reference in New Issue
Block a user