black matrix_operation.py (#2199)

* black matrix_operation.py

* updating DIRECTORY.md

* Update matrix_operation.py

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Co-authored-by: vinayak <itssvinayak@gmail.com>
This commit is contained in:
Christian Clauss
2020-07-14 10:23:14 +02:00
committed by GitHub
parent 749ffd8c6f
commit 23cbe4c352
2 changed files with 12 additions and 9 deletions

View File

@@ -101,8 +101,8 @@ def minor(matrix: List[list], row: int, column: int) -> List[list]:
>>> minor([[1, 2], [3, 4]], 1, 1)
[[1]]
"""
minor = matrix[:row] + matrix[row + 1:]
return [row[:column] + row[column + 1:] for row in minor]
minor = matrix[:row] + matrix[row + 1 :]
return [row[:column] + row[column + 1 :] for row in minor]
def determinant(matrix: List[list]) -> int:
@@ -155,8 +155,7 @@ def _shape(matrix: List[list]) -> list:
return list((len(matrix), len(matrix[0])))
def _verify_matrix_sizes(
matrix_a: List[list], matrix_b: List[list]) -> Tuple[list]:
def _verify_matrix_sizes(matrix_a: List[list], matrix_b: List[list]) -> Tuple[list]:
shape = _shape(matrix_a)
shape += _shape(matrix_b)
if shape[0] != shape[2] or shape[1] != shape[3]:
@@ -170,12 +169,9 @@ def _verify_matrix_sizes(
def main():
matrix_a = [[12, 10], [3, 9]]
matrix_b = [[3, 4], [7, 4]]
matrix_c = [[11, 12, 13, 14], [21, 22, 23, 24],
[31, 32, 33, 34], [41, 42, 43, 44]]
matrix_c = [[11, 12, 13, 14], [21, 22, 23, 24], [31, 32, 33, 34], [41, 42, 43, 44]]
matrix_d = [[3, 0, 2], [2, 0, -2], [0, 1, 1]]
print(
f"Add Operation, {matrix_a} + {matrix_b} ="
f"{add(matrix_a, matrix_b)} \n")
print(f"Add Operation, {matrix_a} + {matrix_b} =" f"{add(matrix_a, matrix_b)} \n")
print(
f"Multiply Operation, {matrix_a} * {matrix_b}",
f"= {multiply(matrix_a, matrix_b)} \n",