[Numpy-discussion] FeatureRequest: support for array construction from iterators

Stephan Sahm Stephan.Sahm at gmx.de
Fri Nov 27 05:37:17 EST 2015

[ this
/discussion refers to numpy issue
​ ​
https://github.com/numpy/numpy/pull/5863#issuecomment-159738368 ]

Dear all,

As far as I can think, the expected functionality of np.array(...) would be
np.array(list(...)) or something even nicer.
Therefore, I like to request a generator/iterator support for np.array(...)
as far as list(...) supports it.

A more detailed reasoning behind this follows now.

In general it seems possible to identify iterators/generators as needed for
this purpose: - someone actually implemented this feature already (see
) - there is ​``type.GeneratorType​`` and ​``​collections.abc.Iterator​``
for ``isinstance​(...)`` check ​- numpy can destinguish them already from
all other types which get well translated into a numpy array​ ​

Given this, I think the general argument goes roughly like the following:

PROS (effect maybe 10% of numpy user or more): - more intuitive overall
behaviour, array(...) = array(list(...)) roughly - python3 compatibility
(see e.g. #5951 <https://github.com/numpy/numpy/issues/5951>) -
compatibility with analog ``__builtin__`` functions (see e.g. #5756
<https://github.com/numpy/numpy/issues/5756>) - all the above make numpy
easier to use in an interactive style (e.g. ipython --pylab) (computation
not that important, however coding time well) CONS (effect less than 0.1%
numpy user I would guess): - might break existing code

which in total, at least for me at this stage, speaks in favour of merging
​ ​
​the already existing
​featurebranch (see
or something similar into numpy master

Discussion, please!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20151127/3a815e89/attachment.html>

More information about the NumPy-Discussion mailing list