Home » Python

Dask Array in Python

Python dask array: Here, we are going to learn about the dask array in python – how to instal dask, how to use it with the array in python?
Submitted by Bestha Radha Krishna, on April 10, 2019

Python Dask Array

Dask is parallel computing python library and it is mainly used to run across multiple systems. Dask is used to process the data efficiently on a different cluster of machines. Dask can completely use all the cores available in the machine.

Dask stores the complete data on the disk and uses chunks of data from the disk for processing. Dask analyzes the large data sets with the help of Pandas data frame and "numpy arrays".

Basically, dask arrays are distributed "numpy arrays". A large "numpy array" is divided into smaller arrays and they are grouped together to form dask array.

Install using this command:

    pip install dask 

Dask array.asarray is used to convert the given input into dask array. It converts lists, tuples, numpy array to dask array.

Program to create a dask array:

Example #1:

import dask.array as p 

rk = [1,2,3,4,5] 	#converts the list into dask array 
d=p.asarray(rk) 
print(d.compute()) 	#print type of d 
print(type(d)) 

r = (1,2,3) 		#converts the tuple into dask array 
k=p.asarray(r) 

print(k.compute()) 	#print type of k 
print(type(k))

Output

[1 2 3 4 5]
<class 'dask.array.core.Array'>
[1 2 3]
<class 'dask.array.core.Array'>

Example #2:

import dask.array as p 
 import numpy as np 
 
 #create a numpy array 
 r=np.arange(5) 
 print(r) 		#print type of numpy array 
 print(type(r)) 	#converting numpy array to dask array 
 
 d=p.asarray(r) 
 print(d.compute()) 
 print(type(d)) 
 
 t=np.array([1,2,3]) 
 print(t) 		#print type of numpy array 
 print(type(t)) 	#converting numpy array to dask array 
 
 f=p.asarray(t) 
 print(f.compute()) #print type of dask array 
 print(type(f))

Output

[0 1 2 3 4]
<class 'numpy.ndarray'>
[0 1 2 3 4]
<class 'dask.array.core.Array'>
[1 2 3]
<class 'numpy.ndarray'>
[1 2 3]
<class 'dask.array.core.Array'>





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL







Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.