numpy.arange(start,stop, step,dtype=None)
Return ndarray by using start, stop, step and dtype.
start | number, Optional,default is 0, Start value of the elements |
stop | number, Optional,Upper limit of start ( value not included ). |
step | number, Optional, default is 1 |
dtype | type of output, Optional, default is dtype of input arguments |
import numpy as np
print(np.arange(0)) # []
print(np.arange(5)) # [0 1 2 3 4]
With start stop and step options
print(np.arange(start=1,stop=5,step=2)) # [1 3]
print(np.arange(1,5))
Output
[1 2 3 4]
Creating empty array
x=np.arange(3,3)
print(x) # []
print(np.arange(start=1,stop=5,step=2)) # [1 3]
print(np.arange(1,5,2)) # [1 3]
print(np.arange(-10,-3,2)) # [-10 -8 -6 -4]
print(np.arange(-3,-10,-2)) # [-3 -5 -7 -9]
print(np.arange(-3,10,3)) # [-3 0 3 6 9]
print(np.arange(.4, 2.8,.7)) # [0.4 1.1 1.8 2.5]
print(np.arange(-2.8, 2,.9)) # [-2.8 -1.9 -1. -0.1 0.8 1.7]
print(np.arange(1,5,dtype=np.int8)) # [1 2 3 4]
print(np.arange(1,5,dtype=np.float64)) # [1. 2. 3. 4.]
Getting the dtype
my_ar=np.arange(1,5,dtype=np.float64)
print(my_ar.dtype) # float64
Numpy
eye()
ones()
bincount()
linspace()
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.