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

josef.pktd@gmai... josef.pktd@gmai...
Tue Jan 31 19:45:52 CST 2012


On Tue, Jan 31, 2012 at 5:35 PM, Travis Oliphant <travis@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 completely agree here.

I also like to keep np.all, np.any, np.max, ...

>>> np.max((i>  0 for i in xrange (10)))
<generator object <genexpr> at 0x046493F0>
>>> max((i>  0 for i in xrange (10)))
True

I used an old-style matplotlib example as recipe yesterday, and the
first thing I did is getting rid of the missing name spaces, and I had
to think twice what amax and amin are.

aall, aany ??? ;)

Josef

>
> It also seems useful to revisit under what conditions 'array' could correctly interpret a generator expression, but in the context of streaming or deferred arrays.
>
> Travis
>
>
> --
> Travis Oliphant
> (on a mobile)
> 512-826-7480
>
>
> On Jan 31, 2012, at 4:22 PM, Robert Kern <robert.kern@gmail.com> wrote:
>
>> On Tue, Jan 31, 2012 at 22:17, Travis Oliphant <travis@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 least.
>>
>> I would rather we deprecate the all() and any() functions in favor of
>> the alltrue() and sometrue() aliases that date back to Numeric.
>> Renaming them to match the builtin names was a mistake.
>>
>> --
>> Robert Kern
>>
>> "I have come to believe that the whole world is an enigma, a harmless
>> enigma that is made terrible by our own mad attempt to interpret it as
>> though it had an underlying truth."
>>   -- Umberto Eco
>> _______________________________________________
>> NumPy-Discussion mailing list
>> NumPy-Discussion@scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion


More information about the NumPy-Discussion mailing list