仅在大陆上绘制数据时,程序将永远运行而不会给出错误 [英] Program runs forever without giving an error when plotting data only on continent

查看:277
本文介绍了仅在大陆上绘制数据时,程序将永远运行而不会给出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图仅在大陆上绘制数据.之前我问过一个问题,并且在此处得到了答案. 现在,当我在代码中实现它时,程序将运行而不会给出错误.

I was trying to plot data only on continent. I asked a question about this before and I've got the answer here. Now when I implemented it in the code, the program will run without giving an error.

但是,它永远运行.当我使用ctrl + C强制停止它时,它可以追溯到"if not (map.is_land(X[i], Y[i])):",因此我认为这里有问题.但我无法弄清楚.

However, it RUNS FOREVER. When I use ctrl + C to force stop it, it traces back to "if not (map.is_land(X[i], Y[i])):", so I think there's something wrong here. But I can't figure it out.

这是代码的一部分,涉及挑选非大陆数据并将其删除:

Here is the part of code that involves picking out non-continental data and removing them:

X, Y = map(Lon,Lat)
ocean = []
for i in range(len(X)):
    if not (map.is_land(X[i], Y[i])):
        ocean.append(i)

X_new = np.delete(X, ocean)
Y_new = np.delete(Y, ocean)
HDO_new = np.delete(HDO, ocean)

推荐答案

由于您使用了for循环,因此程序无论如何都应该停止,唯一的问题是X的大小.我只能给出两个建议:

Since you use a for loop, the program should stop anyway, the only problem is how large is X. I can only give two suggestions:

1)在输入for cicle之前尝试打印len(X)的值以查看大小

1) try to print the value of len(X) before entering the for cicle to see how big is

2)如果使用python 2.x,请尝试使用xrange代替range

2) try to use xrange instead of range, if you use python 2.x

还请记住,使用包含数十万个元素的list似乎很慢. 如果可以的话,最终尝试使用较小的数据样本

Keep also in mind that using list with some hundred thousand element seems to be slow. Eventually try using a smaller data sample, if you can

这篇关于仅在大陆上绘制数据时,程序将永远运行而不会给出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆