简体   繁体   中英

looping through two sets of data in Python

I have two sets of data, one for radar, one for lidar. The files are in csv, and i have added the data to empty lists called radar and lidar. The data is 600x600. Each row of data is in a list. so 600 values per row (and therefore per list). The radar file tells me where the islands of land are in the sea, so any values >150 will be land The lidar will tell me the height of the land. so first i used this code:


for i in range(len(radar)):
    for j in range(len(radar[i])):
        if radar [i][j] > 150:
            radar [i][j] = 'land'
        else:
            radar [i][j] = 'sea'

i now need to get the height values of all the areas classified as land (or land over >100) but dont know how to check simultaneously for land and then find its value. Any ideas?

Assuming radar and lidar are of the same orientation (same size and same access), then you can use the same i and j to access lidar[i][j] once you determine radar is something you need, to get the corresponding lidar measurement for that pixel. So below I made a results list were I add a tuple of (i, j, height) for all cases of land.

results = []

for i in range(len(radar)):
    for j in range(len(radar[i])):
        if radar[i][j] > 150:
            radar[i][j] = 'land'
            results.append((i, j, lidar[i][j]))
        else:
            radar [i][j] = 'sea'

You could then calculate based on that results, or you could copy a matrix of land, or however you want to do the calculations after that, but you should be able to access the height like above which is what you main question was.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM