class TransMatrix object def __init__ self filename str self filename

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class TransMatrix(object):
def __init__(self, filename: str):
self.filename = filename
def count(self) -> list:
with open(self.filename) as f:
arr = [list(map(int, x.split(' '))) for x in f]
new_arr = self.swap_matrix(arr)
return new_arr
def indexes_of_max_element(self, arr: list) -> (int, int):
max_elements = list(map(max, arr))
max_element = max(max_elements)
row = max_elements.index(max_element)
column = arr[row].index(max_element)
return row, column
def swap_matrix(self, arr: list):
row, column = self.indexes_of_max_element(arr)
arr[0], arr[row] = arr[row], arr[0]
for r in range(len(arr)):
arr[r][0], arr[r][column] = arr[r][column], arr[r][0]
return arr