-1

I have 2 matrix (lat and lon) of geograhical data in degrees. I want to convert them to x-y coords for plotting. Error shown is list indices must be integers or slices, not tuple. I am new to python and programming. kindly help

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

The errror message shown at line ew1[a,b]=ew[a,b]-ew[0,0]:

TypeError: list indices must be integers or slices, not tuple
Sky
  • 9
  • 3
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Dec 14 '22 at 10:20
  • 1
    FYI, `ew1=[[0]*3600]*1000` is *extremely* wrong; you just made a `list` that contains 1000 aliases to the *same* 3600 element `list`. – ShadowRanger Dec 14 '22 at 16:52
  • So ew1and ns1 was not even being defined as an array. Thanks for pointing out the error. Thanks very much for replying. – Sky Dec 17 '22 at 19:24

1 Answers1

0

To index a 2d list you use ew1[a][b] instead of ew1[a,b]:

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

Although there's also common 2d list issue here.

But as you are using numpy you can (and should) do:

ew = lon * (180 / np.pi)
ns = lat * (180 / np.pi)
ew1 = ew - ew[0,0]
ns1 = ns - ns[0,91]
Yevhen Kuzmovych
  • 10,940
  • 7
  • 28
  • 48