using MATLAB the following code returns a vector starting from -5 to 5 with elements that has 0.01 difference:
x = -5:0.01:5;
what is the equivalent syntax using numpy
using MATLAB the following code returns a vector starting from -5 to 5 with elements that has 0.01 difference:
x = -5:0.01:5;
what is the equivalent syntax using numpy
This would need an explicit conversion, and probably the intention was to use the limits? - something like:
x = np.linspace(-5,5,int((5-(-5))/.01)+1)
or in general
x = np.linspace(minlimit, maxlimit, int((maxlimit-minlimit)/step)+1)
An alternative is to use numpy arange, and, supposing the range is an exact multiple of the step size, add the step to the second argument of arange:
x = np.arange(-5, 5 + .01, 0.01)
or in general:
x = np.arange(minlimit, maxlimit+step, step)
I am not sure how robust this is against jitter due to limited resolution of floating point values.
based on the comments this was convenient for me:
x = np.linspace(-5,5,1/0.01)