[Tutor] finding a maximum between the absolute difference of several columns

Elaina Ann Hyde elainahyde at gmail.com
Fri Feb 17 02:04:12 CET 2012

Hello all,
   I am still scripting away and have reached my next quandry, this one is
much simpler than the last, basically I read in a file with several
Vhel_fdiff3=max(abs(Vmatch3_1 - Vmatch3_2),abs(Vmatch3_1 -
Vmatch3_3),abs(Vmatch3_3 - Vmatch3_2))
What I would like this to return is the maximum difference in each case, so
I end up with one column which contains only the largest differences.
now I use this to write the condition:

with_v1_3=(Vhel_fdiff3 >= Vdav)

I know the condition works and plots if

 Vhel_fdiff3=(Vmatch3_1 - Vmatch3_2)

for example, and I know this syntax would work if it was numbers instead of

The error is:
Traceback (most recent call last):
  File "double_plot.py", line 109, in <module>
    Vhel_fdiff3=max(abs(Vmatch3_1 - Vmatch3_2),abs(Vmatch3_1 -
Vmatch3_3),abs(Vmatch3_3 - Vmatch3_2))
ValueError: The truth value of an array with more than one element is
ambiguous. Use a.any() or a.all()
So it can't handle the fact that it's columns of numbers and not single
numbers, so my question is, can I solve this without doing a loop around
it... use numpy, or some other function instead?
I've been searching around and haven't found any good ways forward so I
thought one of you might know.  Thanks

PhD Candidate
Department of Physics and Astronomy
Faculty of Science
Macquarie University
North Ryde, NSW 2109, Australia
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120217/95f585f2/attachment.html>

More information about the Tutor mailing list