import numpy as np
A = np.array([3,4,4,3,6])
B = np.array([2,5,2,6,3,6,2,2,5])
def ismember(a, b):
# tf = np.in1d(a,b) # for newer versions of numpy
tf = np.array([i in b for i in a])
u = np.unique(a[tf])
index = np.array([(np.where(b == i))[0][-1] if t else 0 for i,t in zip(a,tf)])
return tf, index
tf,ix=ismember(A,B)
print(tf)
# [ True False False True True]
print(ix)
# [4 0 0 4 5]
print(A[tf])
# [3 3 6]
print(B[ix[tf]])
# [3 3 6]