On Thu, Feb 18, 2016 at 1:15 PM, Antony Lee <[email protected]> wrote:
> Mostly so that there is no performance lost when someone passes range(...) > instead of np.arange(...). At least I had never realized that one is much > faster than the other and always just passed range() as a convenience. > > Antony > > 2016-02-17 10:50 GMT-08:00 Chris Barker <[email protected]>: > >> On Sun, Feb 14, 2016 at 11:41 PM, Antony Lee <[email protected]> >> 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) >> > thanks, I didn't know that the range r here doesn't get eaten by iterating through it while r = (i for i in range(5)) is only good for a single pass. (tried on python 3.4) Josef > >> 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 >> >> [email protected] >> >> _______________________________________________ >> NumPy-Discussion mailing list >> [email protected] >> https://mail.scipy.org/mailman/listinfo/numpy-discussion >> >> > > _______________________________________________ > NumPy-Discussion mailing list > [email protected] > https://mail.scipy.org/mailman/listinfo/numpy-discussion > >
_______________________________________________ NumPy-Discussion mailing list [email protected] https://mail.scipy.org/mailman/listinfo/numpy-discussion
