我在Python中有一个numpy数组,其中包含分类问题的标签。两个初始相同数组合并后派生的数组。在
labels = np.concatenate((labels1, labels2)) #labels1 and labels2 are identical
我想生成正/负对,它将包含来自标签(其中labels1和labels2相等)的所有索引,以及包含负索引的对。例如,如果我的输入如下:
^{pr2}$然后我想以正数对的形式返回:
positive_pairs = {{1, 6}, {1, 7}, {2, 6}, {2, 7}, {3, 8}, {3, 9}, {4, 8}, {4, 9}, {5, 10}} # i dont want to have {1,2} or {3, 4} in within the positives
negative_pairs = {{1, 8}, {1, 9}, ...}
如何在python中这样做?在
编辑:如果标签1和标签2不相等,该怎么办?在
以下是
positive_pairs
的解决方案:negative_pairs
留作练习。在你可以这样完成
^{pr2}$不过,我不确定这是最有效的方法。在
相关问题 更多 >
编程相关推荐