On 01/31/2012 04:13 PM, Benjamin Root wrote: > > > On Tuesday, January 31, 2012, Alan G Isaac <[email protected] > <mailto:[email protected]>> wrote: > > On 1/31/2012 8:26 AM, Neal Becker wrote: > >> I was just bitten by this unexpected behavior: > >> > >> In [24]: all ([i> 0 for i in xrange (10)]) > >> Out[24]: False > >> > >> In [25]: all (i> 0 for i in xrange (10)) > >> Out[25]: True > >> > >> Turns out: > >> In [31]: all is numpy.all > >> Out[31]: True > > > > > >>>> np.array([i> 0 for i in xrange (10)]) > > array([False, True, True, True, True, True, True, True, True, > True], dtype=bool) > >>>> np.array(i> 0 for i in xrange (10)) > > array(<generator object <genexpr> at 0x0267A210>, dtype=object) > >>>> import this > > > > > > Cheers, > > Alan > > > > Is np.all() using np.array() or np.asanyarray()? If the latter, I would > expect it to return a numpy array from a generator. If the former, why > isn't it using asanyarray()?
Your expectation is probably wrong: In [12]: np.asanyarray(i for i in range(10)) Out[12]: array(<generator object <genexpr> at 0x455d9b0>, dtype=object) Dag Sverre _______________________________________________ NumPy-Discussion mailing list [email protected] http://mail.scipy.org/mailman/listinfo/numpy-discussion
