Print unique rows in a given boolean matrix | Given a binary matrix of M X N of integers , you need to return only unique rows of binary array ; The main function that prints all unique rows in a given matrix . ; Traverse through the matrix ; Check if there is similar column is already printed , i . e if i and jth column match . ; If no row is similar ; Print the row ; Driver Code
ROW = 4 NEW_LINE COL = 5 NEW_LINE def findUniqueRows ( M ) : NEW_LINE INDENT for i in range ( ROW ) : NEW_LINE INDENT flag = 0 NEW_LINE for j in range ( i ) : NEW_LINE INDENT flag = 1 NEW_LINE for k in range ( COL ) : NEW_LINE INDENT if ( M [ i ] [ k ] != M [ j ] [ k ] ) : NEW_LINE INDENT flag = 0 NEW_LINE DEDENT DEDENT if ( flag == 1 ) : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT if ( flag == 0 ) : NEW_LINE INDENT for j in range ( COL ) : NEW_LINE INDENT print ( M [ i ] [ j ] , end = " ▁ " ) NEW_LINE DEDENT print ( ) NEW_LINE DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT M = [ [ 0 , 1 , 0 , 0 , 1 ] , [ 1 , 0 , 1 , 1 , 0 ] , [ 0 , 1 , 0 , 0 , 1 ] , [ 1 , 0 , 1 , 0 , 0 ] ] NEW_LINE findUniqueRows ( M ) NEW_LINE DEDENT