C1_W2_Assignment exercise 4_issue with reshape

I’ve been trying to solve this problem. I have an issue with the first line of code

def augmented_to_ref(A, b):    
    ### START CODE HERE ###
    # stack horizontally matrix A and vector b, which needs to be reshaped as a vector (4, 1)

{code removed by mentor}

the output I get is :

I’ve been working on this for 3-4 hours but still unable to find what is going wrong. I submitted the assignment and was graded as fail.

Can someone help me on what needs to be done.

You have a problem here with the parenthesis.
image

The parameter to b.reshape(…) must be a tuple, yours isn’t. Adjust your parenthesis and that should fix it.

I’m missing something here. I changed it and it’s still the same error.

{code removed by mentor}

I made changes as it was given in course yet I get same error.

I think there may be a problem with your “A” matrix or “b” vector.

Check your code for the Exercise 1 section. Then check that you’re using the A and b variables correctly.

They are correct and the previous exercise solutions did pass all of them. I’m kind of stuck here.

{code removed by mentor}

After those cells, do you have any code that modifies A or b?

Also, have you re-named the notebook file?

No code changes. And no I haven’t re-named the notebook. Please help me out. it’s really frustrating I know the exercises and yet I failed. :confused:

Check your private messages in a minute or two.

I’m sorry I really cannot comprehend here I did pass it as tuple. this is in my code: A_system = np.hstack((A, b.reshape((4, 1)))) the below code was provided in “C1_W2_Lab_1_solving_linear_systems_3_variables” A_system = np.hstack((A, b.reshape((3, 1)))) both are the same what i’m I missing ?. I added print statements to check if the matrix is correct it turns out be correct
{code removed by mentor}
. Please find the screenshot here

I have seen the code of other members who posted. It’s same. I still can’t figure it out. please help me out.

Hi @nitincheekatla,

I don’t mentor this course, but the thing I notice from your code is in the last line for multiplying row 3 by -1/17, it replaces the matrix with a row. You are not asked to replace the matrix with a row, but to modify its row 3.

The replacement can explain why your resulting A_ref’s shape is the shape for just one row, but not the shape for a matrix, which is expected.

thank you that did the work for me. I owe you one. Such a silly mistake took me 2 days to figure it out.

Hi @nitincheekatla,

No problem.

As a mentor and a learner, I believe post-mortem may be useful. I know you have spent 2 days on it, but when you are ready, I am going to share how I noticed it.

I don’t mentor this course, so what you shared is literally all I know about that exercise. I did the following:

  1. Your printed messages are very helpful and gave me some context. I believe those were Tom’s suggestions?

  2. I read through all those instructions and none suggests that the shape should change - so my focus becomes: what can change the shape?

  3. I listed the only 4 operations ever used - SwapRows, AddRows, +=, and =

  4. I don’t know if SwapRows and AddRows can go wrong, but for += and =, I can know immediately.

  5. If I didn’t spot anything, I would have asked you to print each A_ref after it is changed, not just A_system and the final A_ref, but every single one in the middle. With those additional prints, I can inspect every one of them and find out which has the problem.

Therefore, even if I had missed it in step 4, I could have found it in step 5. Step 5 looks time-consuming, but that definitely takes less than 2 days :wink:

Good luck!
Raymond

PS: I am going to remove assignment codes that are not allowed to share here for you.

1 Like

Haha…!!! you are right should have debugged it more precisely. Lesson learnt.