-
-
Save K4bl0-Skat3R/fd369228d746cef63cad 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
def soma_matrizes(A, B): | |
soma = [[A[i][j] + B[i][j] for j in range(len(B[0]))] | |
for i in range(len(A))] | |
return soma if soma_possivel(A, B) else "As matrizes nao sao nxn" | |
def mult_matrizes(A, B): | |
mult = [[sum(A[i][k] * B[k][j] for k in range(len(B))) | |
for j in range(len(B[0]))] for i in range(len(A))] | |
return mult if mult_possivel(A, B) else "Operacao nao eh possivel" | |
def soma_possivel(A, B): | |
def quadrada(A): | |
n = len(A[0]) | |
return not False in map(lambda x: len(x) == n, A) | |
return quadrada(A) and quadrada(B) | |
def mult_possivel(A, B): | |
return len(A[0]) == len(B) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment