mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-06 01:56:26 +08:00
Add pep8-naming to pre-commit hooks and fixes incorrect naming conventions (#7062)
* ci(pre-commit): Add pep8-naming to `pre-commit` hooks (#7038) * refactor: Fix naming conventions (#7038) * Update arithmetic_analysis/lu_decomposition.py Co-authored-by: Christian Clauss <cclauss@me.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * refactor(lu_decomposition): Replace `NDArray` with `ArrayLike` (#7038) * chore: Fix naming conventions in doctests (#7038) * fix: Temporarily disable project euler problem 104 (#7069) * chore: Fix naming conventions in doctests (#7038) Co-authored-by: Christian Clauss <cclauss@me.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
@ -27,7 +27,7 @@ def inverse_of_matrix(matrix: list[list[float]]) -> list[list[float]]:
|
||||
[[0.25, -0.5], [-0.3, 1.0]]
|
||||
"""
|
||||
|
||||
D = Decimal # An abbreviation for conciseness
|
||||
d = Decimal # An abbreviation for conciseness
|
||||
|
||||
# Check if the provided matrix has 2 rows and 2 columns
|
||||
# since this implementation only works for 2x2 matrices
|
||||
@ -35,7 +35,7 @@ def inverse_of_matrix(matrix: list[list[float]]) -> list[list[float]]:
|
||||
raise ValueError("Please provide a matrix of size 2x2.")
|
||||
|
||||
# Calculate the determinant of the matrix
|
||||
determinant = D(matrix[0][0]) * D(matrix[1][1]) - D(matrix[1][0]) * D(matrix[0][1])
|
||||
determinant = d(matrix[0][0]) * d(matrix[1][1]) - d(matrix[1][0]) * d(matrix[0][1])
|
||||
if determinant == 0:
|
||||
raise ValueError("This matrix has no inverse.")
|
||||
|
||||
@ -45,4 +45,4 @@ def inverse_of_matrix(matrix: list[list[float]]) -> list[list[float]]:
|
||||
swapped_matrix[1][0], swapped_matrix[0][1] = -matrix[1][0], -matrix[0][1]
|
||||
|
||||
# Calculate the inverse of the matrix
|
||||
return [[float(D(n) / determinant) or 0.0 for n in row] for row in swapped_matrix]
|
||||
return [[float(d(n) / determinant) or 0.0 for n in row] for row in swapped_matrix]
|
||||
|
Reference in New Issue
Block a user