How to create a numpy array within a given range?

PythonNumpyServer Side ProgrammingProgramming

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.

Algorithm

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))

Output

Enter starting value: 5
Enter ending value: 50
Enter Step value: 5
[ 5 10 15 20 25 30 35 40 45]
raja
Published on 16-Mar-2021 10:01:19
Advertisements