Google News
logo
NumPy - Interview Questions
How to create a numpy array sequence given only the starting point, length and the step?
Create a numpy array of length 10, starting from 5 and has a step of 3 between consecutive numbers
 
length = 10
start = 5
step = 3

def seq(start, length, step):
    end = start + (step*length)
    return np.arange(start, end, step)

seq(start, length, step)
# array([ 5,  8, 11, 14, 17, 20, 23, 26, 29, 32])

 

Advertisement