[SciPy-Dev] tricky unary versus binary minus
josef.pktd at gmail.com
josef.pktd at gmail.com
Sat Feb 18 00:25:09 EST 2017
On Sat, Feb 18, 2017 at 12:04 AM, Alan Isaac <alan.isaac at gmail.com> wrote:
> http://python-history.blogspot.com/2010/08/why-pythons-
> integer-division-floors.html
I need floor division for the remaining computation, so that part I'm happy
with.(Actually, when I start to use divmod I have only non-negative numbers)
>>> bwi = 5
>>> np.arange(-bwi // 2, bwi // 2 + 1)
array([-3, -2, -1, 0, 1, 2])
>>> np.arange(-(bwi // 2), bwi // 2 + 1)
array([-2, -1, 0, 1, 2])
the bug hunting was: Why is the window asymmetric?
What threw me off is the operator precedence, what Robert said about
operator precedence is kind of obvious ex-post, but the case where it
matters doesn't show up often enough to automatically think about it, and
the familiar float analogy doesn't apply.
e.g. I avoid remembering some rules by using explicit, defensive parenthesis
>>> 1.5**(-2)
it's commutative
>>> --2 / -3
-0.6666666666666666
>>> ---2 / 3
-0.6666666666666666
>>> ---(2 / 3)
-0.6666666666666666
Josef
>
>
> fwiw,
> Alan
> _______________________________________________
> SciPy-Dev mailing list
> SciPy-Dev at scipy.org
> https://mail.scipy.org/mailman/listinfo/scipy-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20170218/3814310a/attachment.html>
More information about the SciPy-Dev
mailing list