Skip to content

Commit 3a69802

Browse files
committed
get_dimensions() now returns if a single matrix is a square matrix
1 parent 70cc59d commit 3a69802

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

matrix_operations.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def __str__(self) -> str:
1212

1313
@staticmethod
1414
def __get_dimensions(matrix_1: matrix, matrix_2: Optional[matrix] = None) -> \
15-
Union[dimensions, tuple[dimensions, dimensions, bool, bool]]:
15+
Union[tuple[dimensions, bool], tuple[dimensions, dimensions, bool, bool]]:
1616
rows_1: int = len(matrix_1)
1717
cols_1: int = len(matrix_1[0])
1818
dim_1: dimensions = (rows_1, cols_1)
@@ -24,7 +24,8 @@ def __get_dimensions(matrix_1: matrix, matrix_2: Optional[matrix] = None) -> \
2424
compatible_dim: bool = cols_1 == rows_2
2525
return dim_1, dim_2, same_dim, compatible_dim
2626
else:
27-
return dim_1
27+
square: bool = rows_1 == cols_1
28+
return dim_1, square
2829

2930
# noinspection PyUnusedLocal
3031
@staticmethod
@@ -86,7 +87,9 @@ def multiplication(matrix_1: matrix, matrix_2: matrix) -> matrix:
8687
# noinspection PyUnusedLocal
8788
@staticmethod
8889
def transpose(matrix_1: matrix) -> matrix:
89-
dim: dimensions = MatrixOperations.__get_dimensions(matrix_1)
90+
dim: dimensions
91+
square: bool
92+
dim, square = MatrixOperations.__get_dimensions(matrix_1)
9093
transpose_m: matrix = [[0 for cols in range(dim[0])] for rows in range(dim[1])]
9194
for i in range(0, dim[0]):
9295
for j in range(0, dim[1]):

0 commit comments

Comments
 (0)