Numarray question

M

Matt Feinstein

If I try

I get:

array([0, 0, 1], type=Bool)

which is pretty slick, However if I set

I get a runtime error: "An array doesn't make sense as a truth value."

So.. why not? It seems to me that if I could vectorize logical
expressions (a la Matlab), it would be a lot easier to write functions
that will take either scalar or vector input values. Am I missing
something?

Matt Feinstein
 
R

Robert Kern

Matt said:
If I try



I get:

array([0, 0, 1], type=Bool)

which is pretty slick, However if I set

q = 2 < array([1,2,3])
q and q


I get a runtime error: "An array doesn't make sense as a truth value."

So.. why not? It seems to me that if I could vectorize logical
expressions (a la Matlab), it would be a lot easier to write functions
that will take either scalar or vector input values. Am I missing
something?

logical_and(), logical_or(), etc. These will handle arrays of truth
values rather than treating the array as a single truth value like "and"
and "or" will do. The reason why the latter is left undefined is because
there isn't much solid agreement about what the semantics should be. In
the face of ambiguity, numarray refuses the temptation to guess and
forces the user to explicitly request certain behavior via alltrue() or
sometrue() or whatever strikes their fancy.

--
Robert Kern
(e-mail address removed)

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top