延迟函数
您的任务是汇总公司最近 2 周的成本。因为您知道将来会用更多周数重复同样的计算,您希望以便于并行化的方式来编写它。
最近两周的各项成本数组分别为 costs_week_1 和 costs_week_2,并且已将 numpy 以 np 导入。
本练习是课程的一部分
Python 中的 Dask 并行编程
练习说明
- 导入
delayed()函数。 - 将
np.sum()函数延迟执行,并用它分别对costs_week_1和costs_week_2创建延迟求和。 - 将这两个和相加,创建另一个表示总计的 delayed 对象。
- 计算并打印该总计。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Import the delayed function from Dask
from ____ import ____
# Lazily calculate the sums of costs_week_1 and costs_week_2
sum1 = ____(____)(____)
sum2 = ____
# Add the two delayed sums
total = ____
# Compute and print the final answer
print(____)