Asma Kowsar
Asma Kowsar

Reputation: 1

too many indices for array: array is 1-dimensional, but 3 were indexed, what does indexed mean?

 c_scheme = p.pcolor(x, y, np.squeeze(xco2[0,:,:]), cmap = 'jet')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/welcome/.local/lib/python3.8/site-packages/numpy/ma/core.py", line 3224, in __getitem__
    dout = self.data[indx]
IndexError: too many indices for array: array is 1-dimensional, but 3 were indexed

Upvotes: 0

Views: 740

Answers (1)

Stingpie 52
Stingpie 52

Reputation: 13

It would help if I could see how xco2 is defined, but I'll try to answer anyway.

It seems that xco2 is an array created 1-dimensionally. This means the array is only indexed by (the value you are looking for is selected by) a single number. However, here, [0,:,:] is a 3-dimensional index, since there are three arguments in the brackets.

assuming p.pcolor() only needs a single variable out of xco2, you can completely remove np.squeeze, and simply use c_scheme = p.pcolor(x, y, xco2[0], cmap = 'jet')

Upvotes: 1

Related Questions