I’m studying in python. I want to create numpy array in python, start from 0 to 1 with increment 0.1. This is the code:
import numpy as np
t=np.arange(0, 1, 0.1)
print(t)
the result is
[0. 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9]
But "1" is not include in array, how to include 1 in array? Does we manually adding 1 to array, or any other ways?
>Solution :
As stated in the np.arange dccumentation
arange(stop): Values are generated within the half-open interval
[0, stop)(in other words, the interval including start but
excluding stop).
arange(start, stop): Values are generated within the half-open interval[start, stop).
arange(start, stop, step)Values are generated within the half-openinterval [start, stop), with spacing between values given by
step.
So, to include 1, just change to np.arange(0, 1.1, 0.1) (any value
greater than 1 and less or equal with 1.1 would work)
>>> np.arange(0, 1.1, 0.1)
array([0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1. ])