Python List Equality | Program to check if two given matrices are identical

We are given two square matrices of same order. Check if two given matrices are identical.

Examples:

Input :     A = [ [1, 1, 1, 1],
                  [2, 2, 2, 2],
                  [3, 3, 3, 3],
                  [4, 4, 4, 4]]
 
            B = [ [1, 1, 1, 1],
                  [2, 2, 2, 2],
                  [3, 3, 3, 3],
                  [4, 4, 4, 4]]

Output:    Matrices are identical

We have existing solution for this problem please refer C Program to check if two given matrices are identical link. In python any iterable object is comparable so we can solve this problem quickly in python with the help of List Equality.

filter_none

edit
close

play_arrow

link
brightness_4
code

# Function to check if two given matrices are identical
  
def identicalMatrices(A,B):
  
     if A==B:
        print ('Matrices are identical')
     else:
        print ('Matrices are not identical')
  
# Driver program
if __name__ == "__main__":
    A = [ [1, 1, 1, 1],
          [2, 2, 2, 2],
          [3, 3, 3, 3],
          [4, 4, 4, 4]]
   
    B = [ [1, 1, 1, 1],
          [2, 2, 2, 2],
          [3, 3, 3, 3],
          [4, 4, 4, 4]]
    identicalMatrices(A,B)

chevron_right


Output:

Matrices are identical


My Personal Notes arrow_drop_up

Experienced Software Engineer with a demonstrated history of working in the information technology and services industry Skilled in Big Data technologies, Data Structures, Algorithm, Software Development, App Development, Databases, Python, Java, C, and WordPress

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.