Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Numarray question

Reply
Thread Tools

Numarray question

 
 
Matt Feinstein
Guest
Posts: n/a
 
      05-13-2005
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.
 
Reply With Quote
 
 
 
 
Robert Kern
Guest
Posts: n/a
 
      05-13-2005
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
http://www.velocityreviews.com/forums/(E-Mail Removed)

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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
a numarray question avharut@gmail.com Python 3 02-15-2006 11:42 AM
Matplotlib question-- Numeric or numarray? Matt Feinstein Python 1 04-08-2005 02:17 PM
Numarray newbie question ChinStrap Python 5 03-31-2005 10:22 PM
numarray speed question grv Python 11 08-31-2004 04:52 AM
numarray question SunX Python 3 07-19-2004 11:03 PM



Advertisments