How to create a numpy array within a given range?

We have to create a numpy array in the range provided by the user. We will use the arange() function in the numpy library to get our output.


Step1: Import numpy.
Step 2: Take start_value, end_value and Step from the user.
Step 3: Print the array using arange() function in numpy.

Example Code

import numpy as np

start_val = int(input("Enter starting value: "))
end_val = int(input("Enter ending value: "))
Step_val = int(input("Enter Step value: "))
print(np.arange(start_val, end_val, Step_val))


Enter starting value: 5
Enter ending value: 50
Enter Step value: 5
[ 5 10 15 20 25 30 35 40 45]

Updated on: 16-Mar-2021

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started