How to Create a Sequence of Linearly Increasing Values with Numpy Arange?
In this article, we are going to create a sequence of linearly increasing values with Numpy arange() function.
By using arange() function, we can create a sequence of linearly increasing values. This method returns an array with evenly spaced elements as per the interval. The interval mentioned is half opened i.e. [Start, Stop)
Syntax: numpy.arange(start, stop, step)
- start is the starting value
- stop is the ending value
- step is a linear increment value with in the given range. It is optional. By default, it is 1.
- Return an array of elements
numpy.arange(1,10,3) # array([1,4,7])
Here, we have given a range from 1 to 10(start = 1 and stop = 10) but we specified step=3. That means it skips every 3 elements in a range. So In this way, we can increase linearity in data.
Create elements within range with 3-step linearly.
Create elements within range with 5-step linearly.
Create elements within the range of 34 to 50 with 5-step linearly.
[34 39 44 49]
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course