range()Returned is range object , and np.nrange() The return is numpy.ndarray() the
rangeCan be used for iterations, and np.nrange much more than that, it is a sequence that can be used as a vector.
range()Fractional step is not supported, np.arange() support step is decimal
Both are available for iterative
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 IIn range (1,5):... print (i)1234>>> Np.arange (1,5) Array ([1,2,3,4]) >>>range (1,5,.1) Traceback (most recent): File"<stdin>", line1,In <module>typeerror:' Float ' object cannot is interpreted as an integer>>>np.arange (1,5,.5) Array ([1, 1.5, 2., 2.5, 3, 3.5, 4, 4.5]) >>>range (1, Span class= "Hljs-number" >5, 2) >>>for I in Range (1, 5, 2): Span class= "Hljs-keyword" > print (i) 13>>for i in np.arange (1, 5): ... print (i) 1
2
3
4
Python base range () and Np.arange ()