[Numpy-discussion] Constructing array from generator expression/iterator

Sasha ndarray at mac.com
Wed Feb 8 15:05:03 EST 2006

Array constructor does not support arbitrary iterables.  For example:

>>> array(iter([1,2,3]))
array(<listiterator object at 0xf735c5cc>, dtype=object)

In Numeric, it was not possible to try to iterate throught the object
in array constructor because rank-0 arrays were iterable and would
lead to infinite recursion.  Since this problem was fixed in numpy, I
don't see much of a problem in implementing such feature.

On 2/8/06, Stephan Tolksdorf <andorxor at gmx.de> wrote:
> Hi
> I'm new to Numpy and just stumbled over the following problem in Numpy
> 0.9.4:
> array(x**2 for x in range(10))
> does not return what one (me) would suspect, i.e.
> array([x**2 for x in range(10)])
> Is this expected behavior?
> Stephan
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
> for problems?  Stop!  Download the new AJAX search engine that makes
> searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion

More information about the NumPy-Discussion mailing list