+2 votes
in Programming Languages by (77.8k points)
How to find whether elements in a particular row and column in two arrays (matrices) are equal or not?

1 Answer

+1 vote
by (355k points)
selected by
 
Best answer

You can use one of these two functions of Numpy: equal() or not_equal()

They compare arrays (matrices) element-wise and return True/False for each element in the arrays. Check the following example:

>>> import numpy as np
>>> a=np.array([[11,12,13],[14,15,16]])
>>> b=np.array([[12,12,11],[18,9,16]])
>>> a
array([[11, 12, 13],
       [14, 15, 16]])
>>> b
array([[12, 12, 11],
       [18,  9, 16]])
>>> np.equal(a,b)
array([[False,  True, False],
       [False, False,  True]])
>>> np.not_equal(a,b)
array([[ True, False,  True],
       [ True,  True, False]])


...