[Numpy-discussion] fromiter

Travis Oliphant oliphant.travis at ieee.org
Sat Jun 3 03:25:42 EDT 2006

Tim Hochberg wrote:
> Some time ago some people, myself including, were making some noise 
> about having 'array' iterate over iterable object producing ndarrays in 
> a manner analogous to they way sequences are treated. I finally got 
> around to looking at it seriously and once I came to the following three 
> conclusions:
>    1. All I really care about is the 1D case where dtype is specified.
>       This case should be relatively easy to implement so that it's
>       fast. Most other cases are not likely to be particularly faster
>       than converting the iterators to lists at the Python level and
>       then passing those lists to array.
>    2. 'array' already has plenty of special cases. I'm reluctant to add
>       more.
>    3. Adding this to 'array' would be non-trivial. The more cases we
>       tried to make fast, the more likely that some of the paths would
>       be buggy. Regardless of how we did it though, some cases would be
>       much slower than other, which would probably be suprising.

Good job.   I just added a called fromiter for this very purpose.  Right 
now, it's just a stub that calls list(obj) first and then array.  Your 
code would be a perfect fit for it.  I think count could be optional, 
though, to handle cases where the count can be determined from the object.

We'll look forward to your check-in.


More information about the NumPy-Discussion mailing list