Numpy 给定一个子数组(父数组的子集),是否在父数组上找到该数组的索引?

Numpy 给定一个子数组(父数组的子集),是否在父数组上找到该数组的索引?,numpy,indices,numpy-slicing,Numpy,Indices,Numpy Slicing,我有两个数组 Parent array (A) = [2,1,2,1,4,4,3] child array (B) = [1,2,3,4] ( it is actually uniq of A) 我想用numpy在A中找到B元素的标记 在这种情况下,它是 [1,3,0,2,6,4,5] 如果我能把它写成这样的话就太好了 {1: [1,3], 2: [0,2], 3:[6], 4: [4,5] } 循环的在这里看起来并不坏: out_dict = {} for a in enume

我有两个数组

Parent array (A) = [2,1,2,1,4,4,3]

child array (B) = [1,2,3,4] ( it is actually uniq of A) 



我想用numpy在A中找到B元素的标记

在这种情况下,它是

[1,3,0,2,6,4,5]
如果我能把它写成这样的话就太好了

{1: [1,3], 2: [0,2], 3:[6], 4: [4,5] }

循环的
在这里看起来并不坏:

out_dict = {}
for a in enumerate(A):
    if a in out_dict:
        out_dict.append(i)
    else:
        out_dict[a] = [i]

我更喜欢用NumPy。A通常是large@ProtonBoss如果您想要字典输出,numpy实际上没有帮助。@ProtonBoss在另一个注释中,您的第一个请求是
np.argsort(a)
。您是否研究了
唯一的
参数?