[Solved] Matrix, how to solve? [closed]


import random

n = int(input('Введите кол-во столбцов матрицы: ')) #columns
m = int(input('Введите кол-во строк матрицы: '))    #rows
matrix = [[random.randrange(0, 10) for y in range(n)] for x in range(m)]

for i in range(m):
    for j in range(n):
        print(matrix[i][j], end = " ")
    print()

max_x = 0
for i in range(m):
    for j in range(n):
        if max_x < matrix[i].count(matrix[i][j]):
            max_x = i

print(max_x)

If M are number of rows than your first for i in range needs to be m value.
I’m assuming that variable max_x is searched line and by line you mean row. If that’s the case than in max_x save the line with the maximum number of identical. Check if max_x < matrix[i].count(matrix[i][j]) and then save index of that row max_x = matrix.index(matrix[i]).

NOTE: In this case it saves the index of the first row that has the most identical numbers.

5

solved Matrix, how to solve? [closed]