dask.bag.Bag.accumulate
dask.bag.Bag.accumulate¶
- Bag.accumulate(binop, initial=_NoDefault.no_default)[source]¶
Repeatedly apply binary function to a sequence, accumulating results.
This assumes that the bag is ordered. While this is typically the case not all Dask.bag functions preserve this property.
Examples
>>> 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 also takes an optional argument that will be used as the first value.
>>> b.accumulate(add, initial=-1).compute() [-1, 0, 2, 5, 9, 14]