[Numpy-discussion] numpy all unexpected result (generator)

Alan G Isaac alan.isaac@gmail....
Tue Jan 31 09:03:55 CST 2012


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


More information about the NumPy-Discussion mailing list