本文整理汇总了Python中rx.core.Observable.zip方法的典型用法代码示例。如果您正苦于以下问题:Python Observable.zip方法的具体用法?Python Observable.zip怎么用?Python Observable.zip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rx.core.Observable
的用法示例。
在下文中一共展示了Observable.zip方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: variance
# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import zip [as 别名]
def variance(source: ObservableBase) -> ObservableBase:
"""
Returns the statistical variance of the numerical emissions.
The sequence must be finite.
"""
squared_values = source.to_list() \
.flat_map(lambda l: Observable.from_(l).average().flat_map(lambda avg: Observable.from_(l).map(lambda i: i - avg))) \
.map(lambda i: i * i) \
.publish() \
.auto_connect(2)
return Observable.zip(squared_values.sum(), squared_values.count(), lambda sum, ct: sum / (ct - 1))
示例2: zip_list
# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import zip [as 别名]
def zip_list(cls, *args):
"""Merge the specified observable sequences into one observable
sequence by emitting a list with the elements of the observable
sequences at corresponding indexes.
Keyword arguments:
:param Observable cls: Class
:param Tuple args: Observable sources.
:return: Returns an observable sequence containing lists of
elements at corresponding indexes.
:rtype: Observable
"""
def result(*args):
return list(args)
args += (result,)
return Observable.zip(*args)