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

2024/11/15 17:17:02

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

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://en.xdnf.cn/q/119293.html

Related Q&A

KeyError while perfoming solve of two equation

1st i need to get two equation of two longest line length i put lenghths with eq in list like these [( length 1 , eq 1 ) ,.....] sort list with reverse get two equation of two longest line when run the…

Most Pythonic way to merge two dictionnaries having common key/value pair

I have two lists of python dictionnaries : l1 = [{"id":1, "name":"A"}, {"id":2, "name":"B"}] l2 = [{"id":1, "full_name":&…

How to close a while True loop instantly Python

I have a problem ... How can i press P on my keyboard and close the entire program faster ( i would like instantly ) ? The script that i made runs in a loop ( Loop B ) and checks for an image on deskt…

How to replace a value in a list

the program asks user to enter 5 unique number, if the number is already in the list, ask for a new number. after 5 unique numbers have been entered, display the listnumbers = [1,2,3,4,5] count = 0 ind…

How To Reverse A Nested Python List

Given the following nested list,myList=([1,[2,3],[[4,5,[6],7],8,9]])I want to reverse it to be converted into:myList= [[[4, 5, [6], 7], 8, 9], [2, 3], 1]How do I do that? Thanks.

Extract street address from a string

Is there any way to extract a street address from a string (say, email) using python? The address does not come in a set format. It can come without state, zip code, city, but I can guess and supply t…

Convert list in String format back to list of float numbers

str = [ 3.82133931e-01 4.27354313e-02 1.94678816e-03 0.00000000e+000.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+000.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e…

Hawaiian Pronunciation [duplicate]

This question already has an answer here:Hawaiian pronouncer(1 answer)Closed 1 year ago.Hitting a snag with an assignment and thought Id ask for help. The goal is to be able to pronounce Hawaiian words…

mutiline python script in html (pyscript)

Ive tried to use pyscript in html but i can only get it to work in one line of code can somebody help me get it to work for the following code? def vpn(website):from selenium import webdriverfrom sele…

How to write an output of a command to stdout and a file in Python3?

I have a Windows command which I want to write to stdout and to a file. For now, I only have 0 string writen in my file:#!/usr/bin/env python3 #! -*- coding:utf-8 -*-import subprocesswith open(auto_cha…