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

2012-01-31 Thread Neal Becker
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 So numpy.all doesn't seem to do what I would expect when given a generator. Bug?

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

2012-01-31 Thread Robert Kern
On Tue, Jan 31, 2012 at 13:26, Neal Becker ndbeck...@gmail.com 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 So

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

2012-01-31 Thread Dag Sverre Seljebotn
On 01/31/2012 03:07 PM, Robert Kern wrote: On Tue, Jan 31, 2012 at 13:26, Neal Beckerndbeck...@gmail.com wrote: I was just bitten by this unexpected behavior: In [24]: all ([i0 for i in xrange (10)]) Out[24]: False In [25]: all (i0 for i in xrange (10)) Out[25]: True Turns out:

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

2012-01-31 Thread Neal Becker
Dag Sverre Seljebotn wrote: On 01/31/2012 03:07 PM, Robert Kern wrote: On Tue, Jan 31, 2012 at 13:26, Neal Beckerndbeck...@gmail.com wrote: I was just bitten by this unexpected behavior: In [24]: all ([i0 for i in xrange (10)]) Out[24]: False In [25]: all (i0 for i in xrange

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

2012-01-31 Thread Alan G Isaac
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

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

2012-01-31 Thread Benjamin Root
On Tuesday, January 31, 2012, Alan G Isaac alan.is...@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

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

2012-01-31 Thread Robert Kern
On Tue, Jan 31, 2012 at 15:13, Benjamin Root ben.r...@ou.edu 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? [~/scratch] |37 np.asanyarray(i5 for i in range(10)) array(generator

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

2012-01-31 Thread Dag Sverre Seljebotn
On 01/31/2012 04:13 PM, Benjamin Root wrote: On Tuesday, January 31, 2012, Alan G Isaac alan.is...@gmail.com mailto:alan.is...@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)])

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

2012-01-31 Thread Benjamin Root
On Tue, Jan 31, 2012 at 9:18 AM, Robert Kern robert.k...@gmail.com wrote: On Tue, Jan 31, 2012 at 15:13, Benjamin Root ben.r...@ou.edu 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

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

2012-01-31 Thread Dag Sverre Seljebotn
On 01/31/2012 04:35 PM, Benjamin Root wrote: On Tue, Jan 31, 2012 at 9:18 AM, Robert Kern robert.k...@gmail.com mailto:robert.k...@gmail.com wrote: On Tue, Jan 31, 2012 at 15:13, Benjamin Root ben.r...@ou.edu mailto:ben.r...@ou.edu wrote: Is np.all() using np.array() or

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

2012-01-31 Thread Alan G Isaac
On 1/31/2012 10:35 AM, Benjamin Root wrote: A generator is an input that could be converted into an array. def mygen(): i = 0 while True: yield i i += 1 Alan Isaac ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org

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

2012-01-31 Thread Robert Kern
On Tue, Jan 31, 2012 at 15:35, Benjamin Root ben.r...@ou.edu wrote: On Tue, Jan 31, 2012 at 9:18 AM, Robert Kern robert.k...@gmail.com wrote: On Tue, Jan 31, 2012 at 15:13, Benjamin Root ben.r...@ou.edu wrote: Is np.all() using np.array() or np.asanyarray()?  If the latter, I would

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

2012-01-31 Thread Olivier Delalleau
Le 31 janvier 2012 10:50, Robert Kern robert.k...@gmail.com a écrit : On Tue, Jan 31, 2012 at 15:35, Benjamin Root ben.r...@ou.edu wrote: On Tue, Jan 31, 2012 at 9:18 AM, Robert Kern robert.k...@gmail.com wrote: On Tue, Jan 31, 2012 at 15:13, Benjamin Root ben.r...@ou.edu wrote:

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

2012-01-31 Thread Robert Kern
On Tue, Jan 31, 2012 at 15:35, Benjamin Root ben.r...@ou.edu wrote: Furthermore, from the documentation: numpy.asanyarray = asanyarray(a, dtype=None, order=None, maskna=None, ownmaskna=False) Convert the input to an ndarray, but pass ndarray subclasses through. Parameters

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

2012-01-31 Thread Benjamin Root
On Tue, Jan 31, 2012 at 10:05 AM, Olivier Delalleau sh...@keba.be wrote: Le 31 janvier 2012 10:50, Robert Kern robert.k...@gmail.com a écrit : On Tue, Jan 31, 2012 at 15:35, Benjamin Root ben.r...@ou.edu wrote: On Tue, Jan 31, 2012 at 9:18 AM, Robert Kern robert.k...@gmail.com wrote:

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

2012-01-31 Thread Chris Barker
On Tue, Jan 31, 2012 at 6:33 AM, Neal Becker ndbeck...@gmail.com wrote: The reason it surprised me, is that python 'all' doesn't behave as numpy 'all' in this respect - and using ipython, I didn't even notice that 'all' was numpy.all rather than standard python all. namespaces are one honking

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

2012-01-31 Thread Travis Oliphant
I also agree that an exception should be raised at the very least. It might also be possible to make the NumPy any, all, and sum functions behave like the builtins when given a generator. It seems worth exploring at least. Travis -- Travis Oliphant (on a mobile) 512-826-7480 On Jan 31,

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

2012-01-31 Thread Robert Kern
On Tue, Jan 31, 2012 at 22:17, Travis Oliphant tra...@continuum.io wrote: I also agree that an exception should be raised at the very least. It might also be possible to make the NumPy any, all, and sum functions behave like the builtins when given a generator.  It seems worth exploring at

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

2012-01-31 Thread Warren Weckesser
On Tue, Jan 31, 2012 at 4:22 PM, Robert Kern robert.k...@gmail.com wrote: On Tue, Jan 31, 2012 at 22:17, Travis Oliphant tra...@continuum.io wrote: I also agree that an exception should be raised at the very least. It might also be possible to make the NumPy any, all, and sum functions

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

2012-01-31 Thread Travis Oliphant
Actually i believe the NumPy 'any' and 'all' names pre-date the Python usage which first appeared in Python 2.5 I agree with Chris that namespaces are a great idea. I don't agree with deprecating 'any' and 'all' It also seems useful to revisit under what conditions 'array' could correctly

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

2012-01-31 Thread josef . pktd
On Tue, Jan 31, 2012 at 5:35 PM, Travis Oliphant tra...@continuum.io wrote: Actually i believe the NumPy 'any' and 'all' names pre-date the Python usage which first appeared in Python 2.5 I agree with Chris that namespaces are a great idea.  I don't agree with deprecating 'any' and 'all' I