Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created November 30, 2020 17:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/d8bc4dfa5f1eb19af92990ac5820a40d to your computer and use it in GitHub Desktop.
Save parzibyte/d8bc4dfa5f1eb19af92990ac5820a40d to your computer and use it in GitHub Desktop.
"""
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