Skip to content

Commit a3651a6

Browse files
tosemmlpre-commit-ci[bot]tianyizheng02
authored andcommitted
Refactorings (TheAlgorithms#8987)
* use np.dot * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * further improvements using array slicing Co-authored-by: Tianyi Zheng <[email protected]> --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Tianyi Zheng <[email protected]>
1 parent d16e5d7 commit a3651a6

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

Diff for: arithmetic_analysis/gaussian_elimination.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ def retroactive_resolution(
3333

3434
x: NDArray[float64] = np.zeros((rows, 1), dtype=float)
3535
for row in reversed(range(rows)):
36-
total = 0
37-
for col in range(row + 1, columns):
38-
total += coefficients[row, col] * x[col]
39-
36+
total = np.dot(coefficients[row, row + 1 :], x[row + 1 :])
4037
x[row, 0] = (vector[row] - total) / coefficients[row, row]
4138

4239
return x

0 commit comments

Comments
 (0)