當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。