[SciPy-dev] array logical ops error?
perry at stsci.edu
Tue Nov 1 09:26:31 CST 2005
On Nov 1, 2005, at 3:09 AM, Robert Cimrman wrote:
> David M. Cooke wrote:
>> On Oct 31, 2005, at 07:37, Alan G Isaac wrote:
>>> On Mon, 31 Oct 2005, Robert Cimrman apparently wrote:
>>>> is this the expected behaviour?
>>>> IMHO (b * c) == (b and c), (b + c) == (b or c) should hold...
>>> I expected the Boolean operations to yield
>>> element-by-element comparisons. What are they?? In
>>> contrast, the + and * operators give the expected results.
>> Use & and | instead of 'and' and 'or'.
> Thanks, this works as expected. Is there a place where such things are
> documented? I suspect many people would expect 'and' and '&' to have
> same behaviour. Of course, looking at the numeric operations special
> methods should reveal the problem, but who would do it ;)
This is what I usually tell people. But do note doing it this way can
bite people on occasion. This works if the arguments are boolean arrays
or values. But if they aren't the operations are bitwise and thus may
result in surprising results.
More information about the Scipy-dev