0

I have array data, (T). T is temperature as function of time (t) and height (h). I want to pick values of T in the particular height, for example, in 100 km height and then plot it in 2D graphic. Why this loop didn't work?

for j in range(len(tim1)):
    for i in range(len(height1)):
        if height1 == 350. :
            print(i,j,T)

error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 540, in runfile
    execfile(filename, namespace)

    if height1 == 350. :
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Could someone help me? Thank you in advance

3
  • can u share ur some sample data Commented Jun 10, 2014 at 3:10
  • is this numpy? also that error message seems fairly self-explanatory... height1 is an array, == in numpy produces an array of booleans, and you can't test that result for truthiness directly. Commented Jun 10, 2014 at 3:12
  • er, also, you aren't actually testing T anywhere here. Commented Jun 10, 2014 at 3:13

1 Answer 1

1

I may have misinterpreted the question, but you may just need to make sure you are indexing the list when you test for the condition:

for j in range(len(tim1)):
    for i in range(len(height1)):
        if height1[i] == 350. :
            print(i,j,T)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.