dask.bag.Bag.accumulate
dask.bag.Bag.accumulate¶
- Bag.accumulate(binop, initial=_NoDefault.no_default)[源代码]¶
对序列重复应用二元函数,累积结果。
这假设包是有序的。虽然这通常是这种情况,但并非所有 Dask.bag 函数都保留此属性。
示例
>>> import dask.bag as db >>> from operator import add >>> b = db.from_sequence([1, 2, 3, 4, 5], npartitions=2) >>> b.accumulate(add).compute() [1, 3, 6, 10, 15]
Accumulate 还可以接受一个可选参数,该参数将用作第一个值。
>>> b.accumulate(add, initial=-1).compute() [-1, 0, 2, 5, 9, 14]