【发布时间】:2019-09-26 19:17:16
【问题描述】:
我有一组纬度 (lats, min=-88, max=88, shape=89) 和经度 (lons, min=0, max=358, shape=180),还有一个陆地掩膜 (land_mask,海洋=1,陆地=0,形状=(89,180))。
xlon,xlat = np.meshgrid(lons,lats)
PP.pcolormesh(xlon,xlat,land_mask)
PP.colorbar()
PP.show()
我想遍历所有的纬度和经度,并计算那些在海洋上的纬度/经度对,并且什么也不做,即如果在陆地上移动到下一个纬度/经度对。一些伪代码:
# loop over lats
for lat in lats:
# loop over lons
for lon in lons:
# check to see if the current
# lat/lon is in the ocean.
# if True, do something
if (lat,lon) in ocean:
do something
# else if current lat/lon
# over land, do nothing and
# move to the next lat/lon
# pair
else: # ie if over land, skip this point
continue
我不确定如何使用我拥有的 2d 大地掩模来做到这一点。另外,也许有更好的方法来实现比嵌套 for 循环更快和/或更多 Pythonic 的代码?提前致谢。
【问题讨论】:
标签: python numpy multidimensional-array logical-operators