[Numpy-discussion] Issues to fix for 1.7.0rc2.
Sebastian Berg
sebastian@sipsolutions....
Wed Feb 6 04:14:10 CST 2013
On Wed, 2013-02-06 at 10:18 +0100, Dag Sverre Seljebotn wrote:
> On 02/06/2013 08:41 AM, Charles R Harris wrote:
> >
> >
> > On Tue, Feb 5, 2013 at 11:50 PM, Jason Grout
> > <jason-sage@creativetrax.com <mailto:jason-sage@creativetrax.com>> wrote:
> >
> > On 2/6/13 12:46 AM, Charles R Harris wrote:
> > > if we decide to do so
> >
> > I should mention that we don't really depend on either behavior (we
> > probably should have a better doctest testing for an array of None
> > values anyway), but we noticed the oddity and thought we ought to
> > mention it. So it doesn't matter to us which way the decision goes.
> >
> >
> > More Python craziness
> >
> > In [6]: print None or 0
> > 0
> >
> > In [7]: print 0 or None
> > None
>
> To me this seems natural and is just how Python works? I think the rule
> for "or" is simply "evaluate __nonzero__ of left operand, if it is
> False, return right operand".
>
> The reason is so that you can use it like this:
>
Yes, but any() and all() functions in python return forcibly a bool as
one would expect. So probably logical_and.reduce and all should simply
not be the same thing, at least for objects.
Though it is a bit weird that objects do something different from other
types, so maybe it would be OK to say that numpy just differs from
python here, since I am not sure if you can easily change it for the
other types.
Regards,
Sebastian
> x = get_foo() or get_bar() # if get_foo() returns None
> # use result of get_bar
>
> or
>
> def f(x=None):
> x = x or create_default_x()
> ...
>
> I guess that after the "a if expr else b" was introduced this has become
> less common.
>
> Dag Sverre
>
> >
> > Numpy any is consistent with python when considered as logical_or.reduce
> >
> > In [13]: print array([0, None]).any()
> > None
> >
> > In [14]: print array([None, 0]).any()
> > 0
> >
> > This appears to be an __ror__, __or__ inconsistency in python. Note that
> > None possesses neither of those operators.
> >
> > Chuck
> >
> >
> > _______________________________________________
> > 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