{"id":8694,"date":"2021-06-12T10:56:04","date_gmt":"2021-06-12T05:26:04","guid":{"rendered":"https:\/\/python-programs.com\/?p=8694"},"modified":"2021-11-22T18:40:39","modified_gmt":"2021-11-22T13:10:39","slug":"numpy-arange-create-a-numpy-array-of-evenly-spaced-numbers-in-python","status":"publish","type":"post","link":"https:\/\/python-programs.com\/numpy-arange-create-a-numpy-array-of-evenly-spaced-numbers-in-python\/","title":{"rendered":"numpy.arange() : Create a Numpy Array of evenly spaced numbers in Python"},"content":{"rendered":"
This article is all about In this article creating a Numpy array of evenly spaced numbers over a given interval using the function Numpy module in python provides a function Where\u00a0<\/i><\/p>\n But to use this Numpy module we have to import following module i.e.<\/p>\nnumpy.arrange()<\/code>.<\/p>\n
numpy.arrange() :<\/h3>\n
numpy.arrange()<\/code> to create an Numpy Array of evenly space elements within a given interval. Actually it returns an evenly spaced array of numbers from the range-array starting from start point to stop point with equal step intervals.<\/p>\n
Syntax- numpy.<\/span>arange<\/span>([<\/span>start, <\/span>]<\/span>stop, <\/span>[<\/span>step, <\/span>]<\/span>dtype=<\/span>None<\/span>)<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n
\n
import numpy as np<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n
\n
\n
<\/a>Example-1 : Create a Numpy Array containing numbers from 4 to 20 but at equal interval of 2<\/h3>\n<\/div>\n
import numpy as np\r\n# Start = 4, Stop = 20, Step Size = 2\r\n#achieving the result using arrange()\r\nsample_arr = np.arange(4, 20, 2)\r\n#printing the output\r\nprint(sample_arr)<\/pre>\n
Output :\r\n[ 4 6 8 10 12 14 16 18]<\/pre>\n<\/div>\n
<\/a>Example-2 : Create a Numpy Array containing numbers from 1 to 15 but at default interval of 1<\/h3>\n
import numpy as np\r\n# Start = 1, Stop = 15, Step Size = 1(default)\r\n#achieving the result using arrange()\r\nsample_arr = np.arange(1, 15)\r\n#printing the output\r\nprint(sample_arr)<\/pre>\n
Output :\r\n[ 1 2 3 4 5 6 7 8 9 10 11 12 13 14]<\/pre>\n<\/div>\n<\/div>\n