Sort the matrix column | Function to find the transpose of the matrix mat [ ] ; Stores the transpose of matrix mat [ ] [ ] ; Traverse each row of the matrix ; Traverse each column of the matrix ; Transpose matrix elements ; Function to sort the given matrix in row wise manner ; Traverse the row ; Row - Wise Sorting ; Function to print the matrix in column wise sorted manner ; Function call to find transpose of the the matrix mat [ ] [ ] ; Sorting the matrix row - wise ; Calculate transpose of B [ ] [ ] ; Print the matrix mat [ ] [ ] ; Driver Code ; Input ; Function call to print the matrix in column wise sorted manner
def transpose ( mat , row , col ) : NEW_LINE INDENT tr = [ [ 0 for i in range ( row ) ] for i in range ( col ) ] NEW_LINE for i in range ( row ) : NEW_LINE INDENT for j in range ( col ) : NEW_LINE INDENT tr [ j ] [ i ] = mat [ i ] [ j ] NEW_LINE DEDENT DEDENT return tr NEW_LINE DEDENT def RowWiseSort ( B ) : NEW_LINE INDENT for i in range ( len ( B ) ) : NEW_LINE INDENT B [ i ] = sorted ( B [ i ] ) NEW_LINE DEDENT return B NEW_LINE DEDENT def sortCol ( mat , N , M ) : NEW_LINE INDENT B = transpose ( mat , N , M ) NEW_LINE B = RowWiseSort ( B ) NEW_LINE mat = transpose ( B , M , N ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT for j in range ( M ) : NEW_LINE INDENT print ( mat [ i ] [ j ] , end = " ▁ " ) NEW_LINE DEDENT print ( ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT mat = [ [ 1 , 6 , 10 ] , [ 8 , 5 , 9 ] , [ 9 , 4 , 15 ] , [ 7 , 3 , 60 ] ] NEW_LINE N = len ( mat ) NEW_LINE M = len ( mat [ 0 ] ) NEW_LINE sortCol ( mat , N , M ) NEW_LINE DEDENT