Check if a given matrix is Hankel or not | Python 3 Program to check if given matrix is Hankel Matrix or not . ; Function to check if given matrix is Hankel Matrix or not . ; for each row ; for each column ; checking if i + j is less than n ; checking if the element is equal to the corresponding diagonal constant ; checking if the element is equal to the corresponding diagonal constant ; Drivers code
N = 4 NEW_LINE def checkHankelMatrix ( n , m ) : NEW_LINE INDENT for i in range ( 0 , n ) : NEW_LINE INDENT for j in range ( 0 , n ) : NEW_LINE INDENT if ( i + j < n ) : NEW_LINE INDENT if ( m [ i ] [ j ] != m [ i + j ] [ 0 ] ) : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT if ( m [ i ] [ j ] != m [ i + j - n + 1 ] [ n - 1 ] ) : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT DEDENT DEDENT return True NEW_LINE DEDENT n = 4 NEW_LINE m = [ [ 1 , 2 , 3 , 5 , ] , [ 2 , 3 , 5 , 8 , ] , [ 3 , 5 , 8 , 0 , ] , [ 5 , 8 , 0 , 9 ] ] NEW_LINE ( print ( " Yes " ) if checkHankelMatrix ( n , m ) else print ( " No " ) ) NEW_LINE