當前位置: 首頁>>代碼示例>>Python>>正文


Python itertools.ifilterfalse方法代碼示例

本文整理匯總了Python中itertools.ifilterfalse方法的典型用法代碼示例。如果您正苦於以下問題:Python itertools.ifilterfalse方法的具體用法?Python itertools.ifilterfalse怎麽用?Python itertools.ifilterfalse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在itertools的用法示例。


在下文中一共展示了itertools.ifilterfalse方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: mean

# 需要導入模塊: import itertools [as 別名]
# 或者: from itertools import ifilterfalse [as 別名]
def mean(l, ignore_nan=False, empty=0):
    """
    nanmean compatible with generators.
    """
    l = iter(l)
    if ignore_nan:
        l = ifilterfalse(isnan, l)
    try:
        n = 1
        acc = next(l)
    except StopIteration:
        if empty == 'raise':
            raise ValueError('Empty mean')
        return empty
    for n, v in enumerate(l, 2):
        acc += v
    if n == 1:
        return acc
    return acc / n 
開發者ID:edwardzhou130,項目名稱:PolarSeg,代碼行數:21,代碼來源:lovasz_losses.py

示例2: mean

# 需要導入模塊: import itertools [as 別名]
# 或者: from itertools import ifilterfalse [as 別名]
def mean(l, ignore_nan=False, empty=0):
    """
    nanmean compatible with generators.
    """
    l = iter(l)
    if ignore_nan:
        l = ifilterfalse(np.isnan, l)
    try:
        n = 1
        acc = next(l)
    except StopIteration:
        if empty == 'raise':
            raise ValueError('Empty mean')
        return empty
    for n, v in enumerate(l, 2):
        acc += v
    if n == 1:
        return acc
    return acc / n 
開發者ID:sneddy,項目名稱:pneumothorax-segmentation,代碼行數:21,代碼來源:Losses.py

示例3: symmetric_difference

# 需要導入模塊: import itertools [as 別名]
# 或者: from itertools import ifilterfalse [as 別名]
def symmetric_difference(self, other):
        """Return the symmetric difference of two sets as a new set.

        (I.e. all elements that are in exactly one of the sets.)
        """
        result = self.__class__()
        data = result._data
        value = True
        selfdata = self._data
        try:
            otherdata = other._data
        except AttributeError:
            otherdata = Set(other)._data
        for elt in ifilterfalse(otherdata.__contains__, selfdata):
            data[elt] = value
        for elt in ifilterfalse(selfdata.__contains__, otherdata):
            data[elt] = value
        return result 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:20,代碼來源:sets.py

示例4: difference

# 需要導入模塊: import itertools [as 別名]
# 或者: from itertools import ifilterfalse [as 別名]
def difference(self, other):
        """Return the difference of two sets as a new Set.

        (I.e. all elements that are in this set and not in the other.)
        """
        result = self.__class__()
        data = result._data
        try:
            otherdata = other._data
        except AttributeError:
            otherdata = Set(other)._data
        value = True
        for elt in ifilterfalse(otherdata.__contains__, self):
            data[elt] = value
        return result

    # Membership test 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:19,代碼來源:sets.py

示例5: symmetric_difference

# 需要導入模塊: import itertools [as 別名]
# 或者: from itertools import ifilterfalse [as 別名]
def symmetric_difference(self, other):
        """Return the symmetric difference of two sets as a new set.

        (I.e. all elements that are in exactly one of the sets.)
        """
        result = self.__class__()
        data = result._data
        value = True
        selfdata = self._data
        try:
            otherdata = other._data
        except AttributeError:
            otherdata = Set(other)._data
        for elt in ifilterfalse(otherdata.has_key, selfdata):
            data[elt] = value
        for elt in ifilterfalse(selfdata.has_key, otherdata):
            data[elt] = value
        return result 
開發者ID:coin3d,項目名稱:pivy,代碼行數:20,代碼來源:_scons_sets.py

示例6: difference

# 需要導入模塊: import itertools [as 別名]
# 或者: from itertools import ifilterfalse [as 別名]
def difference(self, other):
        """Return the difference of two sets as a new Set.

        (I.e. all elements that are in this set and not in the other.)
        """
        result = self.__class__()
        data = result._data
        try:
            otherdata = other._data
        except AttributeError:
            otherdata = Set(other)._data
        value = True
        for elt in ifilterfalse(otherdata.has_key, self):
            data[elt] = value
        return result

    # Membership test 
開發者ID:coin3d,項目名稱:pivy,代碼行數:19,代碼來源:_scons_sets.py

示例7: unique_everseen

# 需要導入模塊: import itertools [as 別名]
# 或者: from itertools import ifilterfalse [as 別名]
def unique_everseen(iterable, key=None):
    "List unique elements, preserving order. Remember all elements ever seen."
    # unique_everseen('AAAABBBCCDAABBB') --> A B C D
    # unique_everseen('ABBCcAD', str.lower) --> A B C D
    seen = set()
    seen_add = seen.add
    if key is None:
        for element in ifilterfalse(seen.__contains__, iterable):
            seen_add(element)
            yield element
    else:
        for element in iterable:
            k = key(element)
            if k not in seen:
                seen_add(k)
                yield element 
開發者ID:Transportation-Inspection,項目名稱:visual_odometry,代碼行數:18,代碼來源:Ground_Truth.py

示例8: test_ifilterfalse

# 需要導入模塊: import itertools [as 別名]
# 或者: from itertools import ifilterfalse [as 別名]
def test_ifilterfalse():
    yield (verify_same, ifilterfalse, _filterfalse, None,
           partial(le, 4), [3, 4, 5])
    yield (verify_same, ifilterfalse, _filterfalse, None,
           partial(le, 6), [3, 4, 5])
    yield (verify_same, ifilterfalse, _filterfalse, None,
           partial(gt, 3), [])
    yield (verify_same, ifilterfalse, _filterfalse, None,
           None, [0, 3, 0, 0, 1])
    yield (verify_pickle, ifilterfalse, _filterfalse, 1, 0,
           partial(le, 4), [3, 4, 5])
    yield (verify_pickle, ifilterfalse, _filterfalse, 3, 2,
           partial(le, 6), [3, 4, 5])
    yield (verify_pickle, ifilterfalse, _filterfalse, 3, 0,
           partial(le, 6), [3, 4, 5])
    yield (verify_pickle, ifilterfalse, _filterfalse, 3, 0,
           None, [0, 3, 0, 0, 1])
    yield (verify_pickle, ifilterfalse, _filterfalse, 3, 2,
           None, [0, 3, 0, 0, 1]) 
開發者ID:mila-iqia,項目名稱:picklable-itertools,代碼行數:21,代碼來源:__init__.py

示例9: mean

# 需要導入模塊: import itertools [as 別名]
# 或者: from itertools import ifilterfalse [as 別名]
def mean(l, ignore_nan=False, empty=0):
    """
    nanmean compatible with generators.
    """
    l = iter(l)
    if ignore_nan:
        l = ifilterfalse(np.isnan, l)
    try:
        n = 1
        acc = next(l)
    except StopIteration:
        if empty == 'raise':
            raise ValueError('Empty mean')
        return empty
    for n, v in enumerate(l, 2):
        acc += v
    if n == 1:
        return acc
    return acc / n



#
# lovasz hinge for non empty images
# 
開發者ID:tugstugi,項目名稱:pytorch-saltnet,代碼行數:27,代碼來源:lovasz_losses.py


注:本文中的itertools.ifilterfalse方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。