mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-02-17 14:58:10 +00:00
Replacing the generator with numpy vector operations from lu_decomposition.
This commit is contained in:
parent
211247ef82
commit
ad217c6616
|
@ -88,15 +88,19 @@ def lower_upper_decomposition(table: np.ndarray) -> tuple[np.ndarray, np.ndarray
|
||||||
|
|
||||||
lower = np.zeros((rows, columns))
|
lower = np.zeros((rows, columns))
|
||||||
upper = np.zeros((rows, columns))
|
upper = np.zeros((rows, columns))
|
||||||
|
|
||||||
|
# in 'total', the necessary data is extracted through slices
|
||||||
|
# and the sum of the products is obtained.
|
||||||
|
|
||||||
for i in range(columns):
|
for i in range(columns):
|
||||||
for j in range(i):
|
for j in range(i):
|
||||||
total = sum(lower[i][k] * upper[k][j] for k in range(j))
|
total = np.sum(lower[i, :i] * upper[:i, j])
|
||||||
if upper[j][j] == 0:
|
if upper[j][j] == 0:
|
||||||
raise ArithmeticError("No LU decomposition exists")
|
raise ArithmeticError("No LU decomposition exists")
|
||||||
lower[i][j] = (table[i][j] - total) / upper[j][j]
|
lower[i][j] = (table[i][j] - total) / upper[j][j]
|
||||||
lower[i][i] = 1
|
lower[i][i] = 1
|
||||||
for j in range(i, columns):
|
for j in range(i, columns):
|
||||||
total = sum(lower[i][k] * upper[k][j] for k in range(j))
|
total = np.sum(lower[i, :i] * upper[:i, j])
|
||||||
upper[i][j] = table[i][j] - total
|
upper[i][j] = table[i][j] - total
|
||||||
return lower, upper
|
return lower, upper
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user