-
-
Save parzibyte/d8bc4dfa5f1eb19af92990ac5820a40d to your computer and use it in GitHub Desktop.
This file contains 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
""" | |
https://parzibyte.me/blog | |
""" | |
matriz = [ | |
[7.8, 2.5, 10], | |
[20, 15.2, 12], | |
[89, 9, 6.77], | |
] | |
# Lo único que hacemos es sumar todos los valores y dividirlos por los elementos totales | |
# Nota: si la matriz es una matriz "cuadrada" entonces podrías simplemente usar | |
# len(matriz) * len(matriz[0]) | |
elementos = 0 | |
sumatoria = 0 | |
for fila in matriz: | |
for elemento in fila: | |
sumatoria += elemento | |
elementos += 1 | |
promedio = sumatoria / elementos | |
print( | |
f"La suma es {sumatoria} y el promedio es {promedio}, para la matriz que tiene {elementos} elementos" | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment