Matching matches between two numpy arrays

Let's say I have two arrays a and b:

a = np.arange(0,100).reshape(10,2,5)
b = np.arange(50,500).reshape(45,2,5)

      

I need to know how many of the 10 arrays in the arrays a

are in b

. The following function does the job, but it's not efficient enough:

def measure_overlap(array_1, array_2):
    co = 0
    for i in range(0, len(array_1)):
        if array_1[i] in array_2:
            co = co + 1
    return co

measure_overlap(a, b)
5

      

+3


source to share





All Articles