Why was the name "arange" chosen for the numpy function?
Asked Answered
D

2

23

Is there a specific reason the numpy function arange was named so?

People habitually make the typo arrange, assuming it is spelled as the English word, so the choice seems like something of an oversight given that other less ambiguously spelled options (range etc) are unused by numpy.

Was it chosen as a portmanteau of array and range?

Disordered answered 11/3, 2019 at 13:22 Comment(2)
Travis alludes to it in his 2006 book, web.mit.edu/dvp/Public/numpybook.pdf, Quote: "Function similar to Python’s built-in range() function except it returns an ndarray object"Eboni
Shadowing range when importing numpy with * would a nuisance. sum and min are shadowed, but with fewer issues. For example, for i in range(10): is preferable to for i in arange(10):.Eboni
D
29

NumPy derives from an older python library called Numeric (in fact, the first array object built for python). The arange function dates back to this library, and its etymology is detailed in its manual:

arrayrange()

The arrayrange() function is similar to the range() function in Python, except that it returns an array as opposed to a list.

...

arange() is a shorthand for arrayrange().

  • Numeric Manual
    2001 (p. 18-19), 1999 (p.23)

Tellingly, there is another example with array(range(25)) (p.16), which is functionally the same as arrayrange().

Disordered answered 11/3, 2019 at 17:40 Comment(1)
And linspace is for linearly space(vs geomspace and logspace)?Softy
I
2

It is explicitly modelled on the Python range function. The precedent for prefixing a was that in Python 1 there was already a variant of range called xrange.

Inquest answered 11/3, 2019 at 13:30 Comment(4)
Though I wouldn't surprised if arange preceeds xrange. Any idea when xrange was added to Py2?Eboni
@hpaulj, Looking at python.org/doc/versions, it seems to have been added in python2.0, in October 2000.Exceptionable
xrange was in Python 1.5.2 (1998). Maybe earlier, but that would have been before my time.Inquest
xrange has been in python since at least as far back as 1.4 (25 October 1996) docs.python.org/release/1.4/lib/node26.htmlDisordered

© 2022 - 2024 — McMap. All rights reserved.