Created
November 2, 2019 11:53
-
-
Save MM-coder/008080a77a1d1bd306da9953abaee65d to your computer and use it in GitHub Desktop.
Get median of matrix line using python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = [[5,9,19,0,3,-45,7,3,-20], | |
[-19,2,3,-8,3.5,18.9, 24,3.12,42,9], | |
[51,9.7,-9,-20,38,-4.5,17,103,-2.8], | |
[-9,322,33,18,387.5,9018.9,3,0, 2214], | |
[25,900,-19,10,31,-435,75,34,-240], | |
[-2.19,2,3,-8,3.5,18.9, 28,32,2]] | |
import numpy as np | |
def median(lista: list): | |
soma = 0 | |
for i in lista: | |
soma += i | |
media = round(soma / len(lista), 1) | |
return media | |
def maximo(lista: list): | |
maximo = lista[0] | |
for i in lista: | |
if maximo < i: | |
maximo = i | |
return maximo | |
def median_of_maximum_row(lista: list): | |
medians = [] | |
for i in a: | |
media = median(i) | |
medians.append(media) | |
maximum = maximo(medians) | |
index_of_maximum = medians.index(maximum) | |
return np.median((lista[index_of_maximum])) | |
print(median_of_maximum_row(a)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment