用法:
Bag.starmap(func, **kwargs)
使用給定包中的參數元組應用函數。
這類似於
itertools.starmap
,除了它還接受關鍵字參數。在偽代碼中,這可以寫成:>>> def starmap(func, bag, **kwargs): ... return (func(*args, **kwargs) for args in bag)
- func:可調用的
- **kwargs:項目,延遲或對象,可選
要傳遞給
func
的額外關鍵字參數。這些可以是普通對象dask.bag.Item
或dask.delayed.Delayed
。
參數:
例子:
>>> import dask.bag as db >>> data = [(1, 2), (3, 4), (5, 6), (7, 8), (9, 10)] >>> b = db.from_sequence(data, npartitions=2)
對每個參數元組應用一個函數:
>>> from operator import add >>> b.starmap(add).compute() [3, 7, 11, 15, 19]
對每個參數元組應用一個函數,並帶有額外的關鍵字參數:
>>> def myadd(x, y, z=0): ... return x + y + z >>> b.starmap(myadd, z=10).compute() [13, 17, 21, 25, 29]
關鍵字參數也可以是
dask.bag.Item
或dask.delayed.Delayed
的實例:>>> max_second = b.pluck(1).max() >>> max_second.compute() 10 >>> b.starmap(myadd, z=max_second).compute() [13, 17, 21, 25, 29]
相關用法
- Python dask.bag.Bag.frequencies用法及代碼示例
- Python dask.bag.Bag.to_textfiles用法及代碼示例
- Python dask.bag.Bag.repartition用法及代碼示例
- Python dask.bag.Bag.join用法及代碼示例
- Python dask.bag.Bag.accumulate用法及代碼示例
- Python dask.bag.Bag.fold用法及代碼示例
- Python dask.bag.Bag.map_partitions用法及代碼示例
- Python dask.bag.Bag.groupby用法及代碼示例
- Python dask.bag.Bag.reduction用法及代碼示例
- Python dask.bag.Bag.foldby用法及代碼示例
- Python dask.bag.Bag.flatten用法及代碼示例
- Python dask.bag.Bag.remove用法及代碼示例
- Python dask.bag.Bag.random_sample用法及代碼示例
- Python dask.bag.Bag.distinct用法及代碼示例
- Python dask.bag.Bag.topk用法及代碼示例
- Python dask.bag.Bag.any用法及代碼示例
- Python dask.bag.Bag.pluck用法及代碼示例
- Python dask.bag.Bag.filter用法及代碼示例
- Python dask.bag.Bag.to_avro用法及代碼示例
- Python dask.bag.Bag.map用法及代碼示例
注:本文由純淨天空篩選整理自dask.org大神的英文原創作品 dask.bag.Bag.starmap。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。