For example: I have a = np.array([123, 412, 444])
and b = np.array([123, 321])
I want to know if a contains all the elements in b. Is there a simple operation for this? In this case that would not be true.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use set difference to determine what you are looking for. Numpy has a built-in function called numpy.setdiff1d(ar1, ar2):
Example for your case:
So for your case, you would do a set difference you would subtract a from b and obtain an array with elements in b which are not in a. Then you can check if that was empty or not. As you can see, the output is
312, which is an entry present inabut not inb; the length of it is now larger then zero, therefore there were elements inbwhich were not present ina.