小编Roh*_*tra的帖子

“无效的比较器”:重载“ <”运算符时出错

我有一堂课需要排序。使用此类的向量,排序时出现错误“无效比较器”。

我在课堂上超载了“ <”运算符,并遵循严格的弱排序

如本帖所述

sort需要严格的弱排序。你comparator不是一个。除其他外,对于严格的弱排序,comp(x, x)必须为

这是我的代码:

bool outlierScore::operator<(const outlierScore& other) {
    if (score < other.score)
        return score < other.score;
    else if (coreDistance < other.coreDistance)
        return coreDistance < other.coreDistance;
    else if (id < other.id)
        return id < other.id;
    else
        return false;
}
Run Code Online (Sandbox Code Playgroud)

这是重载的运算符函数,它的作用实际上是尝试按离群值按升序排序,其中核心距离用于打破离群值关系,而id用于打破核心距离关系。

Stack Trace显示了此阶段出现的错误。

template <class _Pr, class _Ty1, class _Ty2>
constexpr bool _Debug_lt_pred(_Pr&& _Pred, _Ty1&& _Left, _Ty2&& _Right) _NOEXCEPT_COND(
    noexcept(_Pred(_Left, _Right))
    && noexcept(_Pred(_Right, _Left))) { // …
Run Code Online (Sandbox Code Playgroud)

c++ sorting operator-overloading

5
推荐指数
2
解决办法
266
查看次数

从两个数组创建元素的映射

我有两个数组,它们是聚类算法的输出。是否有可能自动找到关联映射

考虑两个标签数组:

array1 = [0,0,1,2,3]
array2 = [4,4,6,8,7]
Run Code Online (Sandbox Code Playgroud)

从视觉上看,这些看起来是一样的,但对于更大的标签集,我想找到一个像{0:4,1:6,2:8,3:7}.

Python 有什么方法可以做到这一点吗?

我已经查看了类似解决方案的sklearn 指标,但还没有运气。任何帮助,将不胜感激。

python arrays associative-array python-3.x

3
推荐指数
1
解决办法
2180
查看次数