I have quite a simple scenario where I'd like to test whether both elements of a two-dimensional array are (separately) members of a larger array - for example:
full_array = np.array(['A','B','C','D','E','F'])
sub_arrays = np.array([['A','C','F'],
['B','C','E']])
np.isin(full_array, sub_arrays)
Run Code Online (Sandbox Code Playgroud)
This gives me a single dimension output:
array([ True, True, True, False, True, True])
Run Code Online (Sandbox Code Playgroud)
showing whether elements of full_array are present in either of the two sub-arrays. I'd like instead a two-dimensional array showing the same thing for each of the two elements …
我想检查 A 中的元素是否为 B 行。例如:
a=np.array([[0,1],[1,2]]),b=np.array([[1,3],[1,2],[4,3],[2,3]])
Run Code Online (Sandbox Code Playgroud)
我想得到类似的东西[False,True],因为[0,1]a 中不在 b 中,而[1,2]a 中在 b 中。我试过np.isin,但它只适用于元素方面。
希望这是有道理的,并感激地收到任何帮助。
我有两个排序列表,都是非递减顺序.例如,我有一个带有元素的已排序链表[2,3,4,5,6,7...],另一个带有元素[5,6,7,8,9...].
我需要找到两个列表中的所有常见元素.我知道我可以使用for循环和嵌套循环来迭代所有匹配以找到相同的两个元素.但是,有没有另一种方法可以做到这一点,运行时间少于O(n^2)?
我有一个大型数据帧(5000 x 12039),我想获得与numpy数组匹配的列名.
例如,如果我有桌子
m1lenhr m1lenmin m1citywt m1a12a cm1age cm1numb m1b1a m1b1b m1b12a m1b12b ... kind_attention_scale_10 kind_attention_scale_22 kind_attention_scale_21 kind_attention_scale_15 kind_attention_scale_18 kind_attention_scale_19 kind_attention_scale_25 kind_attention_scale_24 kind_attention_scale_27 kind_attention_scale_23
challengeID
1 0.130765 40.0 202.485367 1.893256 27.0 1.0 2.0 0.0 2.254198 2.289966 ... 0 0 0 0 0 0 0 0 0 0
2 0.000000 40.0 45.608219 1.000000 24.0 1.0 2.0 0.0 2.000000 3.000000 ... 0 0 0 0 0 0 0 0 0 0
3 0.000000 35.0 39.060299 2.000000 23.0 1.0 2.0 0.0 2.254198 …Run Code Online (Sandbox Code Playgroud)