Skip to content

Instantly share code, notes, and snippets.

@Mancek
Last active July 6, 2021 21:19
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 Mancek/865d475812f9f564a8ef3e7790608986 to your computer and use it in GitHub Desktop.
Save Mancek/865d475812f9f564a8ef3e7790608986 to your computer and use it in GitHub Desktop.
Sum of even numbers in 3x3 matrix
import numpy as np
def sumEvenNumbersInMatrix(matrix):
return sum(matrix[matrix%2==0])
rows = 3
columns = 3
#Example input
# 1 2 3
# 4 5 6
# 7 8 9
input = [list(map(int, input().split())) for i in range(rows)]
matrix = np.array(input).reshape(rows, columns)
print(sumEvenNumbersInMatrix(matrix))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment