[Numpy-discussion] Suggestion: special-case np.array(range(...)) to be faster
Chris Barker
chris.barker at noaa.gov
Wed Feb 17 13:50:03 EST 2016
On Sun, Feb 14, 2016 at 11:41 PM, Antony Lee <antony.lee at berkeley.edu>
wrote:
> So how can np.array(range(...)) even work?
>
range() (in py3) is not a generator, nor is is a iterator. it is a range
object, which is lazily evaluated, and satisfies both the iterator protocol
and the sequence protocol (at least most of it:
In [*1*]: r = range(10)
In [*2*]: r[3]
Out[*2*]: 3
In [*3*]: len(r)
Out[*3*]: 10
In [*4*]: type(r)
Out[*4*]: range
In [*9*]: isinstance(r, collections.abc.Sequence)
Out[*9*]: True
In [*10*]: l = list()
In [*11*]: isinstance(l, collections.abc.Sequence)
Out[*11*]: True
In [*12*]: isinstance(r, collections.abc.Iterable)
Out[*12*]: True
I'm still totally confused as to why we'd need to special-case range when
we have arange().
-CHB
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20160217/83f54fd6/attachment.html>
More information about the NumPy-Discussion
mailing list