从数组中选取数据

2024-04-25 06:04:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我有数组数据,(T)。T是温度随时间(T)和高度(h)的变化。我想在特定的高度上选取T的值,例如,在100公里的高度上,然后在二维图形中绘制它。 为什么这个循环不起作用?你知道吗

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

错误:

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()

有人能帮我吗?先谢谢你


Tags: 数据in图形forlenif高度line
1条回答
网友
1楼 · 发布于 2024-04-25 06:04:23

我可能误解了这个问题,但您可能只需要确保在测试条件时正在索引列表:

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

相关问题 更多 >