[Numpy-discussion] boolean operations on boolean arrays

2014-04-12 Thread Alan G Isaac
This is a very basic question.
Suppose `a` and `b` are boolean arrays with the same shape.
Are there any considerations besides convenience in choosing
between:

ab   a*b logical_and(a,b)
a|b   a+b logical_or(a,b)
~aTrue-a  logical_not(a)

I somewhat expect the last column to be slowest
as well as least convenient, since it is built to
first convert non-booleans to booleans.
Are there other differences?
Also, is this made clear anywhere in the docs?

Thanks,
Alan Isaac
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] boolean operations on boolean arrays

2014-04-12 Thread Charles R Harris
On Sat, Apr 12, 2014 at 8:02 AM, Alan G Isaac alan.is...@gmail.com wrote:

 This is a very basic question.
 Suppose `a` and `b` are boolean arrays with the same shape.
 Are there any considerations besides convenience in choosing
 between:

 ab   a*b logical_and(a,b)
 a|b   a+b logical_or(a,b)
 ~aTrue-a  logical_not(a)

 I somewhat expect the last column to be slowest
 as well as least convenient, since it is built to
 first convert non-booleans to booleans.
 Are there other differences?
 Also, is this made clear anywhere in the docs?


The Python operators for ndarrays can be dynamically set, but they are
initialized by the ufunc module (don't ask) as follows.

#define BOOL_invert BOOL_logical_not
#define BOOL_negative BOOL_logical_not
#define BOOL_add BOOL_logical_or
#define BOOL_bitwise_and BOOL_logical_and
#define BOOL_bitwise_or BOOL_logical_or
#define BOOL_bitwise_xor BOOL_logical_xor
#define BOOL_multiply BOOL_logical_and
#define BOOL_subtract BOOL_logical_xor

So they are all equivalent to logical_* functions.

Chuck
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] boolean operations on boolean arrays

2014-04-12 Thread Alexander Belopolsky
On Sat, Apr 12, 2014 at 10:02 AM, Alan G Isaac alan.is...@gmail.com wrote:

 Are there any considerations besides convenience in choosing
 between:

 ab   a*b logical_and(a,b)
 a|b   a+b logical_or(a,b)
 ~aTrue-a  logical_not(a)


Boolean - is being deprecated:

https://github.com/numpy/numpy/pull/4105

The choice between | and *+ is best dictated by what is more natural in
your problem domain and how your functions should treat non-boolean types.
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion