MulaiMulai sekarang secara gratis

Delaying functions

You have been tasked with adding up your company's costs for the last 2 weeks. Because you know that you will want to run this same computation in the future with many more weeks, you think it might be a good idea to write it in a way that can be parallelized.

The arrays of costs of items for the last two weeks are available as costs_week_1 and costs_week_2, and numpy has been imported as np.

Latihan ini adalah bagian dari kursus

Parallel Programming with Dask in Python

Lihat Kursus

Petunjuk latihan

  • Import the delayed() function.
  • Delay the np.sum() function and use it to create delayed sums of costs_week_1 and costs_week_2.
  • Add the two sums together to create another delayed object of the total.
  • Compute and print this total.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# 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(____)
Edit dan Jalankan Kode