I'm looking for a way to efficiently get an array of booleans, where given two arrays with equal size a and b, each element is true if the corresponding element of a appears in the corresponding element of b.
For example, the following program:
a = numpy.array([1, 2, 3, 4])
b = numpy.array([[1, 2, 13], [2, 8, 9], [5, 6], [7]])
print(numpy.magic_function(a, b))
Should print
[True, True, False, False]
Keep in mind this function should be the equivalent of
[x in y for x, y in zip(a, b)]
Only numpy-optimized for cases when a and b are big, and each element of b is reasonably small.
b: instead of a fast numpy 2D array of int dtype you only have a 1D array of object dtype.aandb, and each element ofbhaving few elements.bdiffer in length, there's little point in it being an array. Either turn it into a real 2d array, or treat it as a list.