[Numpy-discussion] Deprecate boolean math operators?

josef.pktd at gmail.com josef.pktd at gmail.com
Thu Dec 5 22:33:02 EST 2013

On Thu, Dec 5, 2013 at 5:37 PM, Sebastian Berg
<sebastian at sipsolutions.net> wrote:
> Hey,
> there was a discussion that for numpy booleans math operators +,-,* (and
> the unary -), while defined, are not very helpful. I have set up a quick
> PR with start (needs some fixes inside numpy still):
> https://github.com/numpy/numpy/pull/4105
> The idea is to deprecate these, since the binary operators |,^,| (and
> the unary ~ even if it is weird) behave identical. This would not affect
> sums of boolean arrays. For the moment I saw one "annoying" change in
> numpy, and that is `abs(x - y)` being used for allclose and working
> nicely currently.

I like mask = mask1 * mask2

That's what I learned working my way through scipy.stats.distributions
a long time ago.

But the main thing is that we use boolean often as 0,1 integer array
in the actual calculations, and I only sometimes add the astype(int)

x[:, None] * (y[:, None] == np.unique(y))

I always thought booleans *are* just 0, 1 integers, until last time
there was the discussion we saw the weird + or - behavior.

We also use rescaling to (-1, 1) in statsmodels   y = mask * 2 - 1
(but maybe we convert to integer first)
My guess is that I only use multiplication heavily, where the boolean
is a dummy variable with 0 if male and 1 if female for example.

Nothing serious but nice not to have to worry about casting with
astype(int) first.

x[:, None] * (y[:, None] == np.unique(y)).astype(int)     (Is the
bracket at the right spot ?)


> - Sebastian
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion

More information about the NumPy-Discussion mailing list