What is the equivalent of the following MATLAB code that generates a time vector in Python?
ti = 1:step:len
What is the equivalent of the following MATLAB code that generates a time vector in Python?
ti = 1:step:len
use numpy.arange:
import numpy as np
# ti = np.arange(start, end, step)
ti = np.arange(1,last+step,step)
If you want to go from 1 to 10 with 0.5 as the step (including 1 and 10), you would write it as:
ti = np.arange(1,10.5,0.5)
If you used 10
as the end
argument, ti
would only go to 9.5 because arange
excludes the end
value.