Create an array using arange() function
kodingwindow@kw:~$ python3
...
>>> from numpy import *
>>> arr = arange(0, 50, 2)
>>> arr
array([ 0,  2,  4,  6,  8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32,
       34, 36, 38, 40, 42, 44, 46, 48])
>>> arr = arange(1, 50, 2)
>>> arr
array([ 1,  3,  5,  7,  9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33,
       35, 37, 39, 41, 43, 45, 47, 49])
Create an array using zeros() function
>>> from numpy import *
>>> arr = zeros(5, int)
>>> arr
array([0, 0, 0, 0, 0])

>>> arr + 3
array([3, 3, 3, 3, 3])

>>> arr = zeros(5, float)
>>> arr
array([0., 0., 0., 0., 0.])
Create an array using ones() function
>>> from numpy import *
>>> arr = ones(5, int)
>>> arr
array([1, 1, 1, 1, 1])

>>> arr + 3
array([4, 4, 4, 4, 4])

>>> arr = ones(5, float)
>>> arr
array([1., 1., 1., 1., 1.])
Advertisement