I recently upgraded to numpy 1.9dev. (For improved OpenBlas support).
I have some code that does x-y
Where x
and y
are samples from a probability distribution.
If the distribution is Bernoulli, then they are boolean.
If the distribution is Gaussian, then they are floats.
where depending on the path followed x
and y
might be bools or floats.
I don't have to care as python has duck-typing.
If it can subtract then it is a valid value for x
and y
I get this warning:
DeprecationWarning: numpy boolean subtract (the binary
-
operator) is deprecated, use the bitwise_xor (the^
operator) or the logical_xor function instead.
I have made the warning go away, by casting it to always be a float. This may be a good thing since it makes the code more consistent at a lower level. (Not sold on that as a good thing).
What is the correct action to be taking?
I can't use boolean or bitwise xor as when x
and y
are floats this will break.
It would be ugly to make the code branch on the type of x
and y
.
There is no such thing as subtraction in the realm of Boolean mathematics.
Use the numpy. logical_not() method to negate a numpy array of booleans, e.g. result = numpy. logical_not(arr) . The logical_not() method applies the logical not operator to the elements in the array and returns the result.
numpy. subtract() returns the difference of the two arrays element-wise. The return type is either ndarray or scalar depending on the input type.
The most straightforward way to subtract two matrices in NumPy is by using the - operator, which is the simplification of the np. subtract() method - NumPy specific method designed for subtracting arrays and other array-like objects such as matrices.
maybe you should do:
x=x.astype(numpy.float32)
y=y.astype(numpy.float32)
then
x - y
at least, it works on my case.
Here my solution:
z = (x.astype(np.float32) - y.astype(np.float32)).astype(np.bool)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With