def is_identity ( ) : for index , row in enumerate ( self . dta ) : if row [ index ] == 1 : for num , element in enumerate ( row ) : if num != index : if element != 0 : return False else : return False return True
python judge matrix is identity matrix
Check to see if this matrix is an identity matrix .
def is_identity():
        """Check to see if this matrix is an identity matrix."""
        for index, row in enumerate(self.dta):
            if row[index] == 1:
                for num, element in enumerate(row):
                    if num != index:
                        if element != 0:
                            return False
            else:
                return False

        return True