Last active
June 16, 2021 18:17
-
-
Save ialexpovad/8971c126a01993ba730f61e7a5bd64f0 to your computer and use it in GitHub Desktop.
The function return defferentail number and matricies
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 difference(A,B): | |
''' | |
The function return defferentail number and matricies. | |
parametr A: First variable | |
parametr B: Second variable | |
... | |
return C: result difference | |
''' | |
if type(A)==int and type(B)==int or \ | |
type(A)==float and type(B)==float: | |
return A-B | |
else: | |
m,n,k,p=len(A),len(A[0]),len(B),len(B[0]) | |
if m!=k or n!=p: | |
raise ArithmeticError('Not the same size.') | |
# Initial zeros matrix | |
C=[[0]*n for _ in range(n)] | |
# Perform element by element sum | |
for i in range(m): | |
for j in range(n): | |
C[i][j]=A[i][j]-B[i][j] | |
return C | |
if __name__=='__main__': | |
a=[[4,2],[556,8]] | |
b=[[4,1],[550,4]] | |
print(difference(a, b)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment