Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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?

2 Answers

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?

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 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. :)