Thursday, September 10, 2020

create arrays using arange() function in python

 create arrays using arange() function in python


 

 

create arrays using arange() function in python

========================================

 

The arrange() function in numpy is same as range()

function in python . The arrange function is used in the

following format :

arrange(start,stop,stepsize)

This creates an array with a group of elements from 'start' to one element prior to 'stop' in steps of 'stepsize'.If the

'Stepsize' parameter is omitted , then it is taken as 1 .If the

'start' parameter is omitted ,then start is taken as 0.

 

 

import numpy as np

np.arange(10)

output

[1,2,3,4,5,6,7,8,9]

 

import numpy as np

np.arange(5,10)

output

[5,6,7,8,9]

 

import numpy as np

np.arange(1,10,3)

output

[1,4,7]

 

import numpy as np

np.arange(10,1,-1)

output

[10,9,8,7,6,5,4,3,2]

 

import numpy as np

np.arange(0,10,1.5)

output

[0 , 1.5 , 3 , 4.5 , 6 , 7.5 , 9]

 

import numpy as np

np.arange(2,21,2)

output

[2,4,6,8,10,12,14,16,18,20]

 

 

 

 


No comments:

Post a Comment

Durga Puja in Odisha

 Durga Puja in Odisha