I am looking for an efficient way to check whether all string entries in a certain numpy array are contained in a second numpy array. See the example below. Array_1 would be the minimal animals that should be checked for. The function should return False in case none or part of the animals are contained and True if all three of them (in arbitrary order) are contained.
import numpy as np
array_1 = np.array(['cat', 'dog', 'goat'])
array_2 = np.array(['cat', 'monkey', 'zebra', 'pig', 'goat', 'horse', 'dog'])
array_3 = np.array(['peacock', 'horse', 'zebra', 'pig', 'cat', 'horse', 'dog', 'sheep'])
compare_function(array_1, array_2)
My current solution has definitely too many for loops and if statements inside. I had already a look on numpy array logical operations but it seemed to me that those are not perfect, because my arrays do not have the same length and not necessarily the same animal order!?
numpy.in1d
– Ashwini Chaudharynp.in1d(array_1, array_2).all()
. – Ashwini Chaudhary