human
Find number of transformation to make two Matrix Equal | Python3 program to find number of countOpsation to make two matrix equals.
Update matrix A [ ] [ ] so that only A [ ] [ ] has to be countOpsed.
Check necessary condition for condition for existence of full countOpsation.
If countOpsation is possible calculate total countOpsation.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to find number of transformation to make two Matrix Equal and the other steps required.
 def countOps ( A , B , m , n ) :
	for i in range ( n ) :
		for j in range ( m ) :
			A [ i ] [ j ] -= B [ i ] [ j ] ;
	for i in range ( 1 , n ) :
		for j in range ( 1 , n ) :
			if ( A [ i ] [ j ] - A [ i ] [ 0 ] - A [ 0 ] [ j ] + A [ 0 ] [ 0 ] != 0 ) :
				return - 1 ;
	result = 0 ;
	for i in range ( n ) :
		result += abs ( A [ i ] [ 0 ] ) ;
	for j in range ( m ) :
		result += abs ( A [ 0 ] [ j ] - A [ 0 ] [ 0 ] ) ;
	return ( result ) ;
if __name__ == ' _ _ main _ _ ' :
	A = [ [ 1 , 1 , 1 ] , [ 1 , 1 , 1 ] , [ 1 , 1 , 1 ] ] ;
	B = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ] ;
	print ( countOps ( A , B , 3 , 3 ) ) ;