IndexError: too many indices for array
7 Dec 2025
1 min read
IndexError: too many indices for array
$ python -c "import numpy as np, matplotlib.pyplot as plt; a=np.array([1,2,3]); a[0,0]"
Traceback (most recent call last):
File "<string>", line 1, in <module>
IndexError: too many indices for array
Why this happens
The array has fewer dimensions than your index implies.
Fix
Match indexing to the array’s shape.
Wrong code
import numpy as np
import matplotlib.pyplot as plt
a = np.array([1,2,3])
a[0,0]
Fixed code
import numpy as np
a = np.array([1,2,3])
a[0]