检查数组-值是否包含在另一个数组中?
问题描述:
我想为数组A
中的每个值返回一个布尔值,指示它是否在数组B
中.我猜这应该是一个标准程序,但是我找不到有关如何执行此操作的任何信息.我的尝试如下:
I'd like to return a boolean for each value in array A
that indicates whether it's in array B
. This should be a standard procedure I guess, but I can't find any information on how to do it. My attempt is below:
A = ['User0','User1','User2','User3','User4','User0','User1','User2','User3'
'User4','User0','User1','User2','User3','User4','User0','User1','User2'
'User3','User4','User0','User1','User2','User3','User4','User0','User1'
'User2','User3','User4','User0','User1']
B = ['User3', 'User2', 'User4']
contained = (A in B)
但是,我得到了错误:
ValueError: shape mismatch: objects cannot be broadcast to a single shape
我使用的是numpy,因此首选使用numpy或标准Python的解决方案.
I'm using numpy so any solution using numpy or standard Python would be preferred.