[Numpy-discussion] numpy all unexpected result (generator)
Tue Jan 31 09:35:38 CST 2012
On Tue, Jan 31, 2012 at 9:18 AM, Robert Kern <email@example.com> wrote:
> On Tue, Jan 31, 2012 at 15:13, Benjamin Root <firstname.lastname@example.org> wrote:
> > Is np.all() using np.array() or np.asanyarray()? If the latter, I would
> > expect it to return a numpy array from a generator.
> Why would you expect that?
> |37> np.asanyarray(i>5 for i in range(10))
> array(<generator object <genexpr> at 0xdc24a08>, dtype=object)
> Robert Kern
What possible use-case could there be for a numpy array of generators?
Furthermore, from the documentation:
numpy.asanyarray = asanyarray(a, dtype=None, order=None, maskna=None,
Convert the input to an ndarray, but pass ndarray subclasses through.
a : array_like
*Input data, in any form that can be converted to an array*. This
includes scalars, lists, lists of tuples, tuples, tuples of tuples,
tuples of lists, and ndarrays.
Emphasis mine. A generator is an input that could be converted into an
array. (Setting aside the issue of non-terminating generators such as
those from cycle()).
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion