Week1 Assignment2 sampling function, Fixed

Issue:
a, z, y are all 2-d arrays rather than a vector that we would expect. This would cause the issue at below screenshot.

Reason:
The parameters b and by are both 2-d arrays, of shape (dimension, 1). This would trigger the broadcasting mechanism while calculating a and z. The instruction didn’t mention this. I had to print shapes of each parameter to look for the issue.

Fix:
Use b.ravel() and by.ravel().

1 Like

Thanks for your report.

This is a matter of how you want to control the dimension of variables.

Your implementation is one of the ways. I prefer to control the dimension by myself, since all variables in parameters are 2D-array not a vector. And, a vector handling in numpy is slightly unique, and not portable. So, my approach is different. But, of course, it depends on you. Here is the link related to this topics. For your information.

1 Like