samedi 3 novembre 2018

Checking "Less than" with a potential very small value in Python

Good morning, I had to find the index[i,j] of the greatest value of a matrix of size m x n.

def biggest_value(matrix, rows, columns):
    max_value = -99999999999999999999
    index = 0
    for i in range(0,m):
        for j in range(0,n):
            if max_num < M[i][j]:
                max_num = M[i][j]
                index = (i,j)
    #index = ' '.join([str(i) for i in index.split()])
    return index

Since for some of the test the input is very small (ie -97969584948693858938939848, I was wondering how could I implement this function in a better way, so I cover any potential negative value the function could take as M argument.

Many thanks!

Aucun commentaire:

Enregistrer un commentaire