簡體   English   中英

錯誤是“列表索引必須是整數或切片,而不是元組”

[英]Error is 'list indices must be integers or slices, not tuple'

我有 2 個以度為單位的地理數據矩陣( latlon )。 我想將它們轉換為 xy 坐標以進行繪圖。 顯示的錯誤是list indices must be integers or slices, not tuple 我是 python 和編程的新手。 請幫助

ew=lon*(180/np.pi)
ns=lat*(180/np.pi)
ew1=[[0]*3600]*1000
ns1=[[0]*3600]*1000  
for a in range(0,len(ew1)):
   for b in range(0,len(ew1[0])):  
       ew1[a,b]=ew[a,b]-ew[0,0] # ew[0,0]=center lon coord
       ns1[a,b]=ns[a,b]-ns[0,91] ## ns[0,91]=center lat coord

ew1[a,b]=ew[a,b]-ew[0,0]行顯示的錯誤消息:

TypeError: list indices must be integers or slices, not tuple

要索引 2d 列表,您可以使用ew1[a][b]而不是ew1[a,b]

ew1[a][b] = ew[a][b] - ew[0,0]
ns1[a][b] = ns[a][b] - ns[0,91]

雖然這里也有常見的二維列表問題

但是當您使用 numpy 時,您可以(並且應該)這樣做:

ew = lon * (180 / np.pi)
ns = lat * (180 / np.pi)
ew1 = ew - ew[0,0]
ns1 = ns - ns[0,91]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM