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


Python itertools.filterfalse方法代码示例

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


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

示例1: mean

# 需要导入模块: import itertools [as 别名]
# 或者: from itertools import filterfalse [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: unique_everseen

# 需要导入模块: import itertools [as 别名]
# 或者: from itertools import filterfalse [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
    # straight from the docs, https://docs.python.org/3/library/itertools.html#itertools-recipes
    seen = set()
    seen_add = seen.add
    if key is None:
        for element in itertools.filterfalse(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:MolSSI,项目名称:QCElemental,代码行数:19,代码来源:itertools.py

示例3: _need_update

# 需要导入模块: import itertools [as 别名]
# 或者: from itertools import filterfalse [as 别名]
def _need_update(curr_list, desired_list):
    """
    Checks to see if there are any difference in curr_list or desired_list. If they are different this returns True.

    Args:
        curr_list (list): list of dictionaries
        desired_list (list): list of dictionaries

    Returns:
         bool
    """
    #Checks if items need to be added or removed.
    add = list(itertools.filterfalse(lambda x: x in curr_list, desired_list))
    remove = list(itertools.filterfalse(lambda x: x in desired_list, curr_list))
    if add or remove:
        return True
    return False 
开发者ID:capitalone,项目名称:Particle-Cloud-Framework,代码行数:19,代码来源:elb.py

示例4: _need_update

# 需要导入模块: import itertools [as 别名]
# 或者: from itertools import filterfalse [as 别名]
def _need_update(self, curr_list, desired_list):
        """
        Checks to see if there are any difference in curr_list or desired_list. If they are different this returns True.

        Args:
            curr_list (list): list of dictionaries
            desired_list (list): list of dictionaries

        Returns:
            bool
        """
        #Checks if items need to be added or removed.
        add = list(itertools.filterfalse(lambda x: x in curr_list, desired_list))
        remove = list(itertools.filterfalse(lambda x: x in desired_list, curr_list))
        if add or remove:
            return True
        return False 
开发者ID:capitalone,项目名称:Particle-Cloud-Framework,代码行数:19,代码来源:alb.py

示例5: _need_update

# 需要导入模块: import itertools [as 别名]
# 或者: from itertools import filterfalse [as 别名]
def _need_update(self, curr_list, desired_list):
        """
        Checks to see if there are any differences in curr_list or desired_list. If they are different True is returned.

        Args:
            curr_list (list): list of dictionaries
            desired_list (list): list of dictionaries

        Returns:
             bool
        """
        # Checks if items need to be added or removed.
        add = list(itertools.filterfalse(lambda x: x in curr_list, desired_list))
        remove = list(itertools.filterfalse(lambda x: x in desired_list, curr_list))
        if add or remove:
            return True
        return False 
开发者ID:capitalone,项目名称:Particle-Cloud-Framework,代码行数:19,代码来源:dynamodb_table.py

示例6: filter_control

# 需要导入模块: import itertools [as 别名]
# 或者: from itertools import filterfalse [as 别名]
def filter_control(
        cls, segments: Iterable["Segment"], is_control=False
    ) -> Iterable["Segment"]:
        """Filter segments by ``is_control`` attribute.

        Args:
            segments (Iterable[Segment]): An iterable of Segment instances.
            is_control (bool, optional): is_control flag to match in search.

        Returns:
            Iterable[Segment]: And iterable of Segment instances.
        
        """
        if is_control:
            return filter(attrgetter("is_control"), segments)
        else:
            return filterfalse(attrgetter("is_control"), segments) 
开发者ID:willmcgugan,项目名称:rich,代码行数:19,代码来源:segment.py

示例7: mean

# 需要导入模块: import itertools [as 别名]
# 或者: from itertools import filterfalse [as 别名]
def mean(l, ignore_nan=False, empty=0):
    """
    nanmean compatible with generators.
    """
    l = iter(l)
    if ignore_nan:
        l = filterfalse(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:ansleliu,项目名称:LightNet,代码行数:21,代码来源:utils.py

示例8: unique_everseen

# 需要导入模块: import itertools [as 别名]
# 或者: from itertools import filterfalse [as 别名]
def unique_everseen(iterable, key=None):
    """List unique elements, preserving order. Remember all elements ever seen.

    >>> ''.join(unique_everseen('AAAABBBCCDAABBB'))
    'ABCD'
    >>> ''.join(unique_everseen('ABBCcAD', str.lower))
    'ABCD'

    """
    seen = set()
    seen_add = seen.add
    if key is None:
        for element in filterfalse(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:bioinformed,项目名称:vgraph,代码行数:23,代码来源:iterstuff.py

示例9: unique_everseen

# 需要导入模块: import itertools [as 别名]
# 或者: from itertools import filterfalse [as 别名]
def unique_everseen(iterable, key=None):
    """List unique elements, preserving order. Remember all elements ever seen.

    >>> list(unique_everseen('AAAABBBCCDAABBB'))
    ['A', 'B', 'C', 'D']
    >>> list(unique_everseen('ABBCcAD', str.lower))
    ['A', 'B', 'C', 'D']
    """
    seen = set()
    seen_add = seen.add
    if key is None:
        for element in filterfalse(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:tensorwerk,项目名称:hangar-py,代码行数:22,代码来源:utils.py

示例10: mean

# 需要导入模块: import itertools [as 别名]
# 或者: from itertools import filterfalse [as 别名]
def mean(l, ignore_nan=False, empty=0):
    """
    nanmean compatible with generators.
    """
    l = iter(l)
    if ignore_nan:
        l = filterfalse(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


# --------------------------- Convinient classes --------------------------- 
开发者ID:bonlime,项目名称:pytorch-tools,代码行数:24,代码来源:lovasz.py

示例11: _op_descendants

# 需要导入模块: import itertools [as 别名]
# 或者: from itertools import filterfalse [as 别名]
def _op_descendants(self, op, only):
        """Descendants of the given operator in the quantum circuit.

        Args:
            op (Operator): operator in the quantum circuit
            only (str, None): the type of descendants to return.

                - ``'G'``: only return non-observables (default)
                - ``'O'``: only return observables
                - ``None``: return all descendants

        Returns:
            list[Operator]: descendants in a topological order
        """
        succ = self.circuit.descendants_in_order((op,))
        if only == "O":
            return list(filter(_is_observable, succ))
        if only == "G":
            return list(itertools.filterfalse(_is_observable, succ))
        return succ 
开发者ID:XanaduAI,项目名称:pennylane,代码行数:22,代码来源:base.py

示例12: unique_everseen

# 需要导入模块: import itertools [as 别名]
# 或者: from itertools import filterfalse [as 别名]
def unique_everseen(iterable, key=None):
    """List unique elements, preserving order.

    Remember all elements ever seen

    >>> list(unique_everseen('AAAABBBCCDAABBB'))
    ['A', 'B', 'C', 'D']
    >>> list(unique_everseen('ABBCcAD', str.lower))
    ['A', 'B', 'C', 'D']

    """
    seen = set()
    seen_add = seen.add
    if key is None:
        for element in itertools.filterfalse(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:KarlJorgensen,项目名称:virgin-media-hub3,代码行数:25,代码来源:utils.py

示例13: mean

# 需要导入模块: import itertools [as 别名]
# 或者: from itertools import filterfalse [as 别名]
def mean(l, ignore_nan=True, empty=0):
    """
    nanmean compatible with generators.
    """
    l = iter(l)
    if ignore_nan:
        l = filterfalse(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:lyakaap,项目名称:pytorch-template,代码行数:21,代码来源:losses.py

示例14: mean

# 需要导入模块: import itertools [as 别名]
# 或者: from itertools import filterfalse [as 别名]
def mean(values, ignore_nan=False, empty=0):
    """
    Nanmean compatible with generators.
    """
    values = iter(values)
    if ignore_nan:
        values = ifilterfalse(isnan, values)
    try:
        n = 1
        acc = next(values)
    except StopIteration:
        if empty == "raise":
            raise ValueError("Empty mean")
        return empty
    for n, v in enumerate(values, 2):  # noqa: B007
        acc += v
    if n == 1:
        return acc
    return acc / n 
开发者ID:catalyst-team,项目名称:catalyst,代码行数:21,代码来源:lovasz.py

示例15: get_parsed_py_files

# 需要导入模块: import itertools [as 别名]
# 或者: from itertools import filterfalse [as 别名]
def get_parsed_py_files(self, whitelist=None):
        parsed_py_files = self._parsed_py_files
        if whitelist:
            parsed_py_files = filterfalse(
                lambda parsed_file: parsed_file.is_in_whitelist(whitelist),
                parsed_py_files
            )
        return parsed_py_files 
开发者ID:devmanorg,项目名称:fiasko_bro,代码行数:10,代码来源:repository_info.py


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