How do I print the location (row and column) of the highest value within an array?

Asked

Viewed 594 times

0

Good morning, I’m not able to complete my code, I’ve already used For i in range and for j in range, but I can’t complete the code because I need to store the result in another variable and then see if the results are greater than x, and then print to show me the column and row that is the highest value, I’m using Python along with Pycharm 2016.1

matriz = [[11,12,13,14]
          [15,16,17,18]
          [19,20,21,22]]

for i in range(matriz.__len__()):
    for j in range(matriz.__len__()):

    if matriz [i][j]>x:
  • Please enter the relevant code you have

  • Welcome to Stackoverflow. Share your code to make it easy for people to help you.

  • Thanks for the tip, the matrix is not accepting here as a variable, in pycharm it already accepts

  • You can complete what is inside if sff. Does it give an error? Which?

  • is giving this error, for i in range(matrix.Len()): Indentationerror: Unexpected indent

  • This has to do with the spacing at the beginning of the line

Show 2 more comments

1 answer

-1

def maior(matriz):
    maior, linha, coluna = 0,0,0
    for i in range(len(matriz)):
        for j in range(len(matriz)):
            if matriz[i][j] > maior:
                linha = i
                coluna = j
                maior = matriz[i][j]
    return "Maior Valor %d  posicao matriz[%d][%d]" % (maior,linha,coluna)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.