当前位置: 首页>>代码示例>>Python>>正文


Python hashtable.unique_label_indices方法代码示例

本文整理汇总了Python中pandas._libs.hashtable.unique_label_indices方法的典型用法代码示例。如果您正苦于以下问题:Python hashtable.unique_label_indices方法的具体用法?Python hashtable.unique_label_indices怎么用?Python hashtable.unique_label_indices使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pandas._libs.hashtable的用法示例。


在下文中一共展示了hashtable.unique_label_indices方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: decons_obs_group_ids

# 需要导入模块: from pandas._libs import hashtable [as 别名]
# 或者: from pandas._libs.hashtable import unique_label_indices [as 别名]
def decons_obs_group_ids(comp_ids, obs_ids, shape, labels, xnull):
    """
    reconstruct labels from observed group ids

    Parameters
    ----------
    xnull: boolean,
        if nulls are excluded; i.e. -1 labels are passed through
    """

    if not xnull:
        lift = np.fromiter(((a == -1).any() for a in labels), dtype='i8')
        shape = np.asarray(shape, dtype='i8') + lift

    if not is_int64_overflow_possible(shape):
        # obs ids are deconstructable! take the fast route!
        out = decons_group_index(obs_ids, shape)
        return out if xnull or not lift.any() \
            else [x - y for x, y in zip(out, lift)]

    i = unique_label_indices(comp_ids)
    i8copy = lambda a: a.astype('i8', subok=False, copy=True)
    return [i8copy(lab[i]) for lab in labels] 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:25,代码来源:sorting.py

示例2: test_unique_label_indices

# 需要导入模块: from pandas._libs import hashtable [as 别名]
# 或者: from pandas._libs.hashtable import unique_label_indices [as 别名]
def test_unique_label_indices():

    a = np.random.randint(1, 1 << 10, 1 << 15).astype('i8')

    left = unique_label_indices(a)
    right = np.unique(a, return_index=True)[1]

    tm.assert_numpy_array_equal(left, right,
                                check_dtype=False)

    a[np.random.choice(len(a), 10)] = -1
    left = unique_label_indices(a)
    right = np.unique(a, return_index=True)[1][1:]
    tm.assert_numpy_array_equal(left, right,
                                check_dtype=False) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:17,代码来源:test_algos.py


注:本文中的pandas._libs.hashtable.unique_label_indices方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。