C1 W1 Assignment, round and shape

Hi everyone! I just joined the course, it’s great! I’m excited to learn about transformers as soon as possible.

In the assignment 1, if I return theta as a numpy matrix, then I get this failure:

print(f"The resulting vector of weights is {[round(t, 8) for t in np.squeeze(tmp_theta)]}")

TypeError: type matrix doesn't define __round__ method

So instead, I do theta = theta.tolist() and the issue goes away. However, when I encounter the test, I get


--> 204             assert result_theta.shape == test_case["input"]["input_dict"]["theta"].shape
    205             successful_cases += 1

AttributeError: 'list' object has no attribute 'shape'

So I’m confused. Should we keep theta as a list or as a numpy matrix?

Thank you!


I’ve never seen the numpy matrix class used in any of the Deep Learning courses. I honestly didn’t know there was such a thing. Just use numpy arrays. The theta value should be a numpy array. You’ll notice that they use np.zeros to create the test value for theta in the gradient descent test case. So you should not need to manipulate the type of theta anywhere.

Yeah, you should keep theta as a numpy array. How are you getting the error? There shouldn’t be any rounding involved, its just getting the dot product of x and theta and updating theta.

That works. Thank you!