469,327 Members | 1,207 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,327 developers. It's quick & easy.

Numarray question

If I try
2 < array([1,2,3])
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?

Matt Feinstein

--
There is no virtue in believing something that can be proved to be true.
Jul 19 '05 #1
1 1036
Matt Feinstein wrote:
If I try

2 < array([1,2,3])

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
rk***@ucsd.edu

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

Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by RJS | last post: by
2 posts views Thread by Tim Rowe | last post: by
reply views Thread by Colin J. Williams | last post: by
3 posts views Thread by Alexander Schwaigkofler | last post: by
8 posts views Thread by Russell E. Owen | last post: by
3 posts views Thread by Alex Hunsley | last post: by
3 posts views Thread by SunX | last post: by
11 posts views Thread by grv | last post: by
10 posts views Thread by Bryan | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Purva khokhar | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.