Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Introduction to NumPy Array Organization Indexing

Caitlin Scouler
Caitlin Scouler
7,082 Points

'IndexError: too many indices for array'

Hi guys,

I am following the video but I get an error when inputting:

study_minutes[(1, 0)]

I get:

'IndexError: too many indices for array'

Am I doing something wrong?

3 Answers

In python, if you're referring to a 2D array, you'd approach it as this: study_minutes[1][1] = 360 It's a little annoying sometimes, but for each dimension you add, you just add another [] at the end.

Hopefully this helps.

I think it should be:

study_minutes[1, 0]

He explained that 1, 0 in [1, 0] is actually a tuple (1, 0) but you don't need to write it in the code.

Caitlin Scouler
Caitlin Scouler
7,082 Points

Thanks Dorde, but I still get the same error :(

Caitlin Scouler
Caitlin Scouler
7,082 Points

I just ran the Notebook from the video download and still get an error:

study_minutes[1, 1] = 360         
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-1-0fb6eb80a6ee> in <module>
----> 1 study_minutes[1, 1] = 360

NameError: name 'study_minutes' is not defined

Any idea why guys?

I had similar problems, I think it's because we're running the code out of order, or you've closed and opened the page. Try 'Kernel: Restart & Run All'. He goes through the error in the next video. :)