本文整理匯總了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
#