[Numpy-discussion] numpy all unexpected result (generator)
Benjamin Root
ben.root at ou.edu
Tue Jan 31 10:13:54 EST 2012
On Tuesday, January 31, 2012, Alan G Isaac <alan.isaac at gmail.com> 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()?
Ben Root
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20120131/b5df357a/attachment.html>
More information about the NumPy-Discussion
mailing list