close

How to compare Two Arrays in Python

Hello guys. How are you all? I hope you all fine. In this tutorial we will learn about how to compare Two Arrays in Python. so without wasting time lets learn about of this.

How to compare Two Arrays in Python

  1. compare Two Arrays in Python

    to compare Two Arrays in Python just Use numpy.allclose() . By using numpy.allclose() you can compare Two Arrays in Python. So lets learn about of this without wasting time by given below example: import numpy as np ary1 = np.array([11,12,14,16,17]) ary2 = np.array([11,13,14,15,17]) ary3 = np.array([11,13,14.00001,15,17]) print(np.allclose(ary1,ary2)) print(np.allclose(ary3,ary2)) Output : False True

  2. How to compare Two Arrays in Python

    to compare Two Arrays in Python just Use == and numpy.all() .By using == and numpy.all() you can compare Two Arrays in Python. So lets learn about of this without wasting time by given below example: import numpy as np ary1 = np.array([11,12,14,16,17]) ary2 = np.array([11,13,14,15,17]) ary3 = np.array([11,13,14.00001,15,17]) print((ary1==ary2).all()) print((ary3==ary2).all()) Output : False False

  3. python compare arrays

    To compare Two Arrays in Python just Use numpy.allclose() . By using numpy.allclose() you can compare Two Arrays in Python. So lets learn about of this without wasting time by given below example: import numpy as np ary1 = np.array([11,12,14,16,17]) ary2 = np.array([11,13,14,15,17]) ary3 = np.array([11,13,14.00001,15,17]) print(np.allclose(ary1,ary2)) print(np.allclose(ary3,ary2)) Output : False True

Method 1: compare Two Arrays Using numpy.allclose()

By using numpy.allclose() you can compare Arrays. So lets learn about of this without wasting time by given below example:

import numpy as np
ary1 = np.array([11,12,14,16,17])
ary2 = np.array([11,13,14,15,17])
ary3 = np.array([11,13,14.00001,15,17])
print(np.allclose(ary1,ary2))
print(np.allclose(ary3,ary2))

Output :

False
True

Method 2: Use == and numpy.all()

By using == and numpy.all() you can compare Two Arrays. So lets learn about of this without wasting time by given below example:

import numpy as np
ary1 = np.array([11,12,14,16,17])
ary2 = np.array([11,13,14,15,17])
ary3 = np.array([11,13,14.00001,15,17])
print((ary1==ary2).all())
print((ary3==ary2).all())

Output :

False
False

Conclusion

It’s all About this Tutorial. Hope all methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which method worked for you?

Also, Read

Leave a Comment