本文整理汇总了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
示例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
示例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
示例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
示例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
示例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
示例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
示例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])
示例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
#