mirror of
https://hub.njuu.cf/TheAlgorithms/Python.git
synced 2023-10-11 13:06:12 +08:00
Fix type error in strassen_matrix_multiplication.py
(#8784)
* Fix type error in strassen_matrix_multiplication.py * updating DIRECTORY.md --------- Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
parent
4b79d771cd
commit
c93659d7ce
@ -294,6 +294,7 @@
|
|||||||
* [Mergesort](divide_and_conquer/mergesort.py)
|
* [Mergesort](divide_and_conquer/mergesort.py)
|
||||||
* [Peak](divide_and_conquer/peak.py)
|
* [Peak](divide_and_conquer/peak.py)
|
||||||
* [Power](divide_and_conquer/power.py)
|
* [Power](divide_and_conquer/power.py)
|
||||||
|
* [Strassen Matrix Multiplication](divide_and_conquer/strassen_matrix_multiplication.py)
|
||||||
|
|
||||||
## Dynamic Programming
|
## Dynamic Programming
|
||||||
* [Abbreviation](dynamic_programming/abbreviation.py)
|
* [Abbreviation](dynamic_programming/abbreviation.py)
|
||||||
|
@ -112,17 +112,19 @@ def strassen(matrix1: list, matrix2: list) -> list:
|
|||||||
[[139, 163], [121, 134], [100, 121]]
|
[[139, 163], [121, 134], [100, 121]]
|
||||||
"""
|
"""
|
||||||
if matrix_dimensions(matrix1)[1] != matrix_dimensions(matrix2)[0]:
|
if matrix_dimensions(matrix1)[1] != matrix_dimensions(matrix2)[0]:
|
||||||
raise Exception(
|
msg = (
|
||||||
"Unable to multiply these matrices, please check the dimensions. \n"
|
"Unable to multiply these matrices, please check the dimensions.\n"
|
||||||
f"Matrix A:{matrix1} \nMatrix B:{matrix2}"
|
f"Matrix A: {matrix1}\n"
|
||||||
|
f"Matrix B: {matrix2}"
|
||||||
)
|
)
|
||||||
|
raise Exception(msg)
|
||||||
dimension1 = matrix_dimensions(matrix1)
|
dimension1 = matrix_dimensions(matrix1)
|
||||||
dimension2 = matrix_dimensions(matrix2)
|
dimension2 = matrix_dimensions(matrix2)
|
||||||
|
|
||||||
if dimension1[0] == dimension1[1] and dimension2[0] == dimension2[1]:
|
if dimension1[0] == dimension1[1] and dimension2[0] == dimension2[1]:
|
||||||
return [matrix1, matrix2]
|
return [matrix1, matrix2]
|
||||||
|
|
||||||
maximum = max(dimension1, dimension2)
|
maximum = max(*dimension1, *dimension2)
|
||||||
maxim = int(math.pow(2, math.ceil(math.log2(maximum))))
|
maxim = int(math.pow(2, math.ceil(math.log2(maximum))))
|
||||||
new_matrix1 = matrix1
|
new_matrix1 = matrix1
|
||||||
new_matrix2 = matrix2
|
new_matrix2 = matrix2
|
Loading…
x
Reference in New Issue
Block a user