当前位置: 首页>>代码示例>>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;未经允许,请勿转载。