Program runs forever without giving an error when plotting data only on continent [closed]

别说谁变了你拦得住时间么 提交于 2019-12-13 10:26:47

问题


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.

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)

回答1:


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) try to print the value of len(X) before entering the for cicle to see how big is

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

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



来源:https://stackoverflow.com/questions/13800056/program-runs-forever-without-giving-an-error-when-plotting-data-only-on-continen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!