human
Swap upper and lower triangular halves of a given Matrix | Function to swap laterally inverted images of upper and lower triangular halves of a given matrix.
Store the matrix elements from upper & lower triangular halves.
Traverse the matrix mat [ ] [ ].
Find the index.
If current element lies on the principal diagonal.
If current element lies below the principal diagonal.
If current element lies above the principal diagonal.
Traverse again to swap values.
Find the index.
Principal diagonal.
Below main diagonal.
Above main diagonal.
Traverse the matrix and pr.
Driver Code.
Given Matrix mat [ ] [ ].
Swap the upper and lower triangular halves"
Solution in Python:
assistant
#Here is code to swap upper and lower triangular halves of a given Matrix and the other steps required.
 def ReverseSwap ( mat , n ) :
	lowerEle = [ [ ] for i in range ( n ) ]
	upperEle = [ [ ] for i in range ( n ) ]
	index = 0
	for i in range ( n ) :
		for j in range ( n ) :
			index = abs ( i - j )
			if ( i == j ) :
				continue
			elif ( j < i ) :
				lowerEle [ index ] . append ( mat [ i ] [ j ] )
			else :
				upperEle [ index ] . append ( mat [ i ] [ j ] )
	for i in range ( n ) :
		for j in range ( n ) :
			index = abs ( i - j )
			if ( i == j ) :
				continue
			elif ( j < i ) :
				mat [ i ] [ j ] = upperEle [ index ] [ - 1 ]
				del upperEle [ index ] [ - 1 ]
			else :
				mat [ i ] [ j ] = lowerEle [ index ] [ - 1 ]
				del lowerEle [ index ] [ - 1 ]
	for i in range ( n ) :
		for j in range ( n ) :
			print ( mat [ i ] [ j ] , end = " ▁ " )
		print ( )
if __name__ == ' _ _ main _ _ ' :
	mat = [ [ 1 , 2 ] , [ 4 , 5 ] ]
	N = len ( mat )
	ReverseSwap ( mat , N )