ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> numpy-discussion
numpy-discussion
[Numpy-discussion] a==b for numpy arrays
by Abel Daniel other posts by this author
Dec 11 2006 10:10AM messages near this date
Re: [Numpy-discussion] fromfile and tofile access with a tempfile.TemporaryFile() | Re: [Numpy-discussion] a==b for numpy arrays
> 
Hi!

My unittests got broken because 'a==b' for numpy arrays returns an
array instead of returning True or False:

> >> import numpy
> >> a = numpy.array([1, 2])
> >> b = numpy.array([1, 4])
> >> a==b
array([True, False], dtype=bool)

This means, for example:
> >> if a==b:
...   print 'equal'
...
Traceback (most recent call last):
  File "<stdin> ", line 1, in ?
ValueError: The truth value of an array with more than one element is ambiguous.
Use a.any() or a.all()
> >>


Now, I think that having a way of getting an element-wise comparison
(i.e. getting an array of bools) is great. _But_ why make that the
result of a '==' comparison? Is there any actual code that does, for
example
> >> result_array = a==b
or any variant thereof?

Thanks in advance,
Daniel


_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@[...].org
http://projects.scipy.org/mailman/listinfo/numpy-discussion
Thread:
Abel Daniel
Robert Kern
Abel Daniel
David Goldsmith
Johannes Loehnert
Robert Kern
Steve Lianoglou
Steve Lianoglou
Christopher Barker
Keith Goodman
Tim Hochberg
David Huard

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved