Anne, thank you, this was the example I was looking for. Indeed A!=B
would not work as expected if the bool(A) always returned A.all(). Now
I can teach my student why there is no automatic conversion from
boolean arrays to booleans.
== Olivier
On 18/04/2008, Anne Archibald <[EMAIL PROTECTED]> wro
On Sat, Apr 19, 2008 at 1:32 AM, Joe Harrington <[EMAIL PROTECTED]> wrote:
> What wasn't obvious was how to cast an array to bool.
Just like any other type:
x.astype(bool)
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by ou
> Just cast your arrays to booleans if you want to do boolean operations
> on them.
It turns out there's an even better way: logical_and() and its friends
do boolean operations on arrays.
IDL solves the problem exactly as numpy does, erroring on arrays in
conditionals and short-circuiting boolean
On 18/04/2008, Robert Kern <[EMAIL PROTECTED]> wrote:
> On Fri, Apr 18, 2008 at 3:33 PM, Joe Harrington <[EMAIL PROTECTED]> wrote:
> > For that matter, is there a reason logical operations don't work on
> > arrays other than booleans? What about:
>
> The keywords "and", "or", and "not" only wor
On Fri, 18 Apr 2008, Joe Harrington apparently wrote:
> For that matter, is there a reason logical operations don't work on
> arrays other than booleans? What about:
> import numpy
> x = numpy.ones((10), dtype='Bool')
> y = numpy.ones((10), dtype='Bool')
> y[6] = False
> z = x and y # logical
On Fri, Apr 18, 2008 at 3:33 PM, Joe Harrington <[EMAIL PROTECTED]> wrote:
> For that matter, is there a reason logical operations don't work on
> arrays other than booleans? What about:
The keywords "and", "or", and "not" only work on bool objects; Python
tries to convert the operands using boo
For that matter, is there a reason logical operations don't work on
arrays other than booleans? What about:
import numpy
x = numpy.ones((10), dtype='Bool')
y = numpy.ones((10), dtype='Bool')
y[6] = False
z = x and y # logical AND: this one fails with an error about arrays
On 18/04/2008, Olivier <[EMAIL PROTECTED]> wrote:
> Let's restrict the discussion the case to boolean arrays (dtype bool),
> since all the comparisons (A==B, A!=B, A arrays).
>
> So I have an array filled with booleans. Is there a reason not to map
> "bool(A)" to "A.all()" but instead raise an
Hi,
I must say, I agree with the other posters here, that it is not
completely obvious to me that:
a = np.array([True, False])
bool(a)
should return False. Especially given:
L = [True, False]
bool(L)
returns True.
Given that it's not completely obvious, and
a.all()
is completely obvious
Let's restrict the discussion the case to boolean arrays (dtype bool),
since all the comparisons (A==B, A!=B, A wrote:
> On Fri, 18 Apr 2008, Olivier Verdier apparently wrote:
> > What is ambiguous about "bool(A==B)"?
>
> A==B is an array. Compare:
>
> >>> bool([])
> False
> >>> bool([0
On Fri, 18 Apr 2008, Olivier Verdier apparently wrote:
> What is ambiguous about "bool(A==B)"?
A==B is an array. Compare:
>>> bool([])
False
>>> bool([0])
True
Even if you decide the second should be false,
what about [0,1]? (I.e., all or any?)
Cheers,
Alan Isaac
__
On Fri, Apr 18, 2008 at 8:43 AM, Matthieu Brucher
<[EMAIL PROTECTED]> wrote:
>
>
> 2008/4/18, Olivier Verdier <[EMAIL PROTECTED]>:
> > I certainly didn't mean that "A==B" should return a boolean!!
> >
> > "A==B" should return an array of boolean as it does now. This is all
> right.
> >
> > *However
2008/4/18, Olivier Verdier <[EMAIL PROTECTED]>:
>
> I certainly didn't mean that "A==B" should return a boolean!!
>
> "A==B" should return an array of boolean as it does now. This is all
> right.
>
> *However* "bool(A==B)" should return a boolean, *not* raise an
> exception. Why raise an exception?
I certainly didn't mean that "A==B" should return a boolean!!
"A==B" should return an array of boolean as it does now. This is all right.
*However* "bool(A==B)" should return a boolean, *not* raise an
exception. Why raise an exception? What is ambiguous about
"bool(A==B)"??
This is what happens
On Fri, Apr 18, 2008 at 01:11:37PM +0200, Olivier Verdier wrote:
> In mathematics, if I compare two function, it means that I compare on
> all its "coordinates". If I say "f < g" I mean "f(x) < g(x) for all
> x".
>
> The same holds for a vector, if I write "v == w" I mean "v[i] == w[i]
> for all i
In mathematics, if I compare two function, it means that I compare on
all its "coordinates". If I say "f < g" I mean "f(x) < g(x) for all
x".
The same holds for a vector, if I write "v == w" I mean "v[i] == w[i]
for all i".
How come this doesn't work in numpy? And why the message about the
truth
16 matches
Mail list logo