1.range()
Returned is range object
, and np.arange()
The return is numpy.ndarray()
the
range
Can be used for iterations, and np.arange
much more than that, it is a sequence that can be used as a vector.
2. range()
step is not supported decimal, np.arange()
support step is decimal
3. Both are available for iterative
4. Both have three parameters, starting with the first argument, the third parameter is the step, and the data series that does not include the second argument before the second argument
In a sense, the interval between the iterator and the STL is the same, that is, the left-closed-right-open interval. [first, last)
or to write without rigor.[first:step:last)
>>>range (1,5) range (1,5) >>>tuple (range (1, 5)) (1, 2, 3, 4) >>>list (range (1, 5)) [1, 2, 3, 4] >>>r = Range (1, 5) >>>type (r) <class ' range ' >>>>for i in range (1, 5): ... . Print (i) 1234>>> np.arange (1, 5) array ([1, 2, 3, 4]) >>>range (1, 5,. 1) Traceback (most recent call last): C2/>file "<stdin>", line 1, in <module>typeerror: ' Float ' object cannot is interpreted as an INTEGER>>&G T;np.arange (1, 5,. 5) Array ([1., 1.5, 2., 2.5, 3., 3.5, 4., 4.5]) >>>range (1, 5, 2) >>>for I in range (1, 5, 2): ... Print (i) 13>>for i in Np.arange (1, 5): ... Print (i) 1234
Note: The range () is canceled in python3.x, and Xrange is renamed to Range.
Xrange () is also used as a loop, except that Xrang (0,10) does not return a list, returning the Xrange object. Each call returns one of these values.
Xrange performance is better when a large number is returned or when a frequent break is required. Arange and Xrange no difference, and in a large number of times Xrang more superior, later coding when try to use xrange.
Python range function and numpy arange function