How to use for loop with dask for parallel processing?

This recipe helps you use for loop with dask for parallel processing

Recipe Objective

How to use for loop with dask for parallel processing.

We will transform the function inc to be used parallely with the help of dask delayed, and we will show you the visualizaion of the for loop to understand parallel working of it.

Step 1- Importing Libraries.

from dask import delayed

Step 2- Defining a function.

We will define a incremental function which will increase the value by 2 in a for loop.

def inc(x): return x + 2

Step 3- Applying delayed.

We will apply dask delayed in the for loop to run inc function parallely. data = [1, 2, 3, 4, 5] results = [] for x in data: y = delayed(inc)(x) results.append(y)

Step 4- Displaying results.

We will print the results of calculating addition and final computing.

addition = delayed(sum)(results) print("Before addition:", addition) calculate = addition.compute() print("After calculating :", calculate)

Step 5- Visualizing

Visualizing the whole addition process that was done in parallel.

addition.visualize()

What Users are saying..

profile image

Anand Kumpatla

Sr Data Scientist @ Doubleslash Software Solutions Pvt Ltd
linkedin profile url

ProjectPro is a unique platform and helps many people in the industry to solve real-life problems with a step-by-step walkthrough of projects. A platform with some fantastic resources to gain... Read More

Relevant Projects

PyTorch Project to Build a LSTM Text Classification Model
In this PyTorch Project you will learn how to build an LSTM Text Classification model for Classifying the Reviews of an App .

Classification Projects on Machine Learning for Beginners - 2
Learn to implement various ensemble techniques to predict license status for a given business.

Build a Text Generator Model using Amazon SageMaker
In this Deep Learning Project, you will train a Text Generator Model on Amazon Reviews Dataset using LSTM Algorithm in PyTorch and deploy it on Amazon SageMaker.

Build a Multi Class Image Classification Model Python using CNN
This project explains How to build a Sequential Model that can perform Multi Class Image Classification in Python using CNN

Recommender System Machine Learning Project for Beginners-1
Recommender System Machine Learning Project for Beginners - Learn how to design, implement and train a rule-based recommender system in Python

Recommender System Machine Learning Project for Beginners-2
Recommender System Machine Learning Project for Beginners Part 2- Learn how to build a recommender system for market basket analysis using association rule mining.

AWS MLOps Project for Gaussian Process Time Series Modeling
MLOps Project to Build and Deploy a Gaussian Process Time Series Model in Python on AWS

Tensorflow Transfer Learning Model for Image Classification
Image Classification Project - Build an Image Classification Model on a Dataset of T-Shirt Images for Binary Classification

Build Real Estate Price Prediction Model with NLP and FastAPI
In this Real Estate Price Prediction Project, you will learn to build a real estate price prediction machine learning model and deploy it on Heroku using FastAPI Framework.

Time Series Forecasting Project-Building ARIMA Model in Python
Build a time series ARIMA model in Python to forecast the use of arrival rate density to support staffing decisions at call centres.