Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9b31b68

Browse files
committed
FEAT Implemented function to return a matrix transposition
1 parent c0254eb commit 9b31b68

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

‎main.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
# ---------------------------------------------------------------------------------------------------------
99

1010

11+
import random as generator
12+
13+
14+
# ---------------------------------------------------------------------------------------------------------
15+
16+
1117
def is_between_zero_and_one(x: float, y: float) -> bool:
1218
"""Return true if the floats x and y exist between 0 and 1 else otherwise"""
1319
return (0 < x < 1) and (0 < y < 1)
@@ -64,6 +70,22 @@ def print_int_array(the_array: [int]) -> None:
6470
# ---------------------------------------------------------------------------------------------------------
6571

6672

73+
def matrix_transposition(the_matrix: [[int]]) -> [[int]]:
74+
rows = len(the_matrix)
75+
cols = len(the_matrix[0]) # the number of columns remain constant
76+
77+
transposed_matrix = [[0] * rows for _ in range(cols)]
78+
79+
for i in range(cols):
80+
for j in range(rows):
81+
transposed_matrix[i][j] = the_matrix[j][i]
82+
83+
return transposed_matrix
84+
85+
86+
# ---------------------------------------------------------------------------------------------------------
87+
88+
6789
def main():
6890
"""For testing"""
6991
test_x: float = 0.1
@@ -80,6 +102,11 @@ def main():
80102
[6, 5, 2]
81103
]
82104

105+
test_int_matrix = [[0] * 2 for _ in range(3)]
106+
for i in range(3):
107+
for j in range(2):
108+
test_int_matrix[i][j] = generator.randint(0, 9)
109+
83110
test_int_array = [5, 7, 6, 9, 3, 8, 2, 4, 1, 10]
84111

85112
print(is_between_zero_and_one(test_x, test_y))
@@ -95,6 +122,14 @@ def main():
95122
print_int_array(test_int_array)
96123
print()
97124

125+
print()
126+
print("- Matrix")
127+
print_two_dm_int_array(test_int_matrix)
128+
129+
print()
130+
print("- Transposition")
131+
print_two_dm_int_array(matrix_transposition(test_int_matrix))
132+
98133

99134
# ---------------------------------------------------------------------------------------------------------
100135

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /