22

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?

iacob
  • 20,084
  • 6
  • 92
  • 119
  • 3
    Travis alludes to it in his 2006 book, http://web.mit.edu/dvp/Public/numpybook.pdf, Quote: "Function similar to Python’s built-in range() function except it returns an ndarray object" – hpaulj Mar 11 '19 at 17:11
  • 2
    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):`. – hpaulj Mar 11 '19 at 17:56

2 Answers2

24

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

iacob
  • 20,084
  • 6
  • 92
  • 119
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.

BoarGules
  • 16,440
  • 2
  • 27
  • 44
  • 1
    Though I wouldn't surprised if `arange` preceeds `xrange`. Any idea when `xrange` was added to Py2? – hpaulj Mar 11 '19 at 17:07
  • @hpaulj, Looking at https://www.python.org/doc/versions/, it seems to have been added in python2.0, in October 2000. – user2699 Mar 11 '19 at 17:22
  • `xrange` was in Python 1.5.2 (1998). Maybe earlier, but that would have been before my time. – BoarGules Mar 11 '19 at 17:23
  • 1
    `xrange` has been in python since at least as far back as 1.4 (25 October 1996) https://docs.python.org/release/1.4/lib/node26.html – iacob Mar 11 '19 at 18:01