Search code examples
pythonnumpynumpy-ndarray

What is the 'a' in numpy.arange?


What does the 'a' in numpy's numpy.arange method stand for, and how does it differ from a simple range produced by Python's builtin range method (definitionally, not in terms of performance and whatnot)?

I tried looking online for an answer to this, but all I find is tutorials for how to use numpy.arange by GeeksForGeeks and co.


Solution

  • You can inspect the return types and reason about what it could mean that way:

    print(type(range(0,5))) 
    import numpy as np  
    print(type(np.arange(0,5)))
    

    Which prints:

    <class 'range'>
    <class 'numpy.ndarray'>
    

    Here's a related question: Why was the name "arange" chosen for the numpy function?

    1. Some people do from numpy import * which would shadow range which causes problems.
    2. Naming the function arrayrange was not chosen because it's too long to type.