C1W2 Programming assignment exercise 2

Hello , I have been stuck on exercise 2 for far too long , this is the error I am getting
An exception was thrown while running your function: index 7 is out of bounds for axis 0 with size 3.
Input matrix:
[[1 0 0 5]
[0 1 0 6]
[0 0 1 7]]
I tried understanding from other discussions but wasnt able to understand anything as the code they used wasnt permitted to be posted

@ssani

could you share a screenshot of your error without sharing the codes

regards
dp

sure ,

index = code removed by moderator), i was trying to guess if this is where i am making a mistake

please don’t post codes here, following guidelines helps everyone. You can send a screenshot of your codes by personal DM. Click on my name and then message.

Probably the code next to recalling index is creating a different output than expected which I am suspecting.

A python exception trace should point to the line that is “throwing”. Look at that line of code and figure out which value is being used as the index. Clearly 7 is not a valid index value for a 3 x 4 matrix. So where did that index value get generated? The bug is probably not on the line that throws, but somewhere before that. Now your job is to track the evidence backwards one step at a time to find where the bad index value came from.

One recommendation would be to take the failing test case and work it out with pencil and paper first, so that you have a clear picture in your mind of all the steps that need to happen in your code. Then add print statements to your code so that you can see what is happening. Then the question is where things go off the rails from what should be happening.

okay will check my code once again properly :+1:

1 Like

hi i am still struggling with that error and cant really understand where i am going wrong

also the error which is shown in the notebook and while grading is completely different

If you are getting an error in the notebook, there is really no point in submitting to the grader. The first order of business is to pass the tests in the notebook. Once you do that, then it’s time to worry about the grader, which usually has different test cases that cover more things.

Maybe it’s time to get more direct help. I will send you a DM about how to do that.

1 Like

I am also facing a similar problem. Can anybody help me with the code? I can send you the code upon request.

You must be treating a numpy scalar object as an iterable. If you are not able to find the issue with that clue, then I will send you a DM about how to proceed.

@ssani

Hi, sorry for delayed response, you are actually using an obsolete copy of assignment. You need to get a fresh copy and re-do your assignment and see the way you wrote codes, once you get the fresh copy I am confident you will pass the test by yourself.

I am sharing a link on how to get a fresh copy, follow the point 1a (you can save a copy of your current assignment for your referral

Let me know if you need help!! and sorry for delayed response.

Regards
DP

@Birendra2024

Same issue hold for you, please get a fresh copy and re-do assignment, follow point 1a

Let me know if you require further assistance.

Regards
DP

yeah will try that, thank you

Seems your issue resolved!!! @ssani

Keep learning!!!

regards
DP

yes i was actually using wrong function for index , the programme was to iterate over the columns of the substitution row and there was no utilisation of index in th entire code.

1 Like

You were using an old copy, so not completely your fault, your codes were actually were clear, so you are good to go :slight_smile:

Regards
DP