Python base range () and Np.arange ()

Source: Internet
Author: User

    • 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 ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.