如何在Python中查找交叉索引和值?

时间:2017-08-11 14:34:07

标签: python matlab numpy

我尝试将代码从Matlab转换为python 我在Matlab中有代码:

[value, iA, iB] = intersect(netA{i},netB{j});

我在python中寻找代码,找到A和B共有的值,以及索引向量ia和ib(对于每个公共元素,它在A中的第一个索引和在B中的第一个索引)。

我尝试使用不同的解决方案,但我收到了不同长度的矢量。试图使用numpy.in1d / intersect1d,返回坏的不是相同的值。 我尝试做的事情:

def FindoverlapIndx(self,a, b):
    bool_a = np.in1d(a, b)
    ind_a = np.arange(len(a))
    ind_a = ind_a[bool_a]
    ind_b = np.array([np.argwhere(b == a[x]) for x in ind_a]).flatten()
    return ind_a, ind_b

 IS=np.arange(IDs[i].shape[0])[np.in1d(IDs[i], R_IDs[j])]
 IR = np.arange(R_IDs[j].shape[0])[np.in1d(R_IDs[j],IDs[i])]

我收到了不同长度的索引。但两者的长度必须与Matlab intersect中的长度相同。

0 个答案:

没有答案
相关问题