x = np.arange(0.3, 12.5, 0.6)
print(x)
[ 0.3 0.9 1.5 2.1 2.7 3.3 3.9 4.5 5.1 5.7 6.3 6.9 7.5 8.1 8.7 9.3 9.9 10.5 11.1 11.7 12.3]
x = np.arange(0.3, 12.5, 0.6,int)
print(x)
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
x = np.arange(0.3, 12.5, 0.6)
print(x)
[ 0.3 0.9 1.5 2.1 2.7 3.3 3.9 4.5 5.1 5.7 6.3 6.9 7.5 8.1 8.7 9.3 9.9 10.5 11.1 11.7 12.3]
x = np.arange(0.3, 12.5, 0.6,int)
print(x)
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
First let's skip the complexity of a float step, and use a simple integer start and stop:
In [141]: np.arange(0,5)
Out[141]: array([0, 1, 2, 3, 4])
In [142]: np.arange(0,5, dtype=int)
Out[142]: array([0, 1, 2, 3, 4])
In [143]: np.arange(0,5, dtype=float)
Out[143]: array([0., 1., 2., 3., 4.])
In [144]: np.arange(0,5, dtype=complex)
Out[144]: array([0.+0.j, 1.+0.j, 2.+0.j, 3.+0.j, 4.+0.j])
In [145]: np.arange(0,5, dtype='datetime64[D]')
Out[145]:
array(['1970-01-01', '1970-01-02', '1970-01-03', '1970-01-04','1970-01-05'], dtype='datetime64[D]')
Even bool
work, within a certain range:
In [149]: np.arange(0,1, dtype=bool)
Out[149]: array([False])
In [150]: np.arange(0,2, dtype=bool)
Out[150]: array([False, True])
In [151]: np.arange(0,3, dtype=bool)
ValueError: no fill-function for data-type.
In [156]: np.arange(0,3).astype(bool)
Out[156]: array([False, True, True])
There are 2 possible boolean values, so asking for more should produce some sort of error.
arange
is compiled code, so we can't readily examine its logic (but you are welcome to search for the C code on github).
The examples show that it does, in some sense convert the parameters into the corresponding dtype
, and perform an iteration on that. It doesn't simply generate the range and convert to dtype at the end.