Function initialize_parameters looks very simple - dimensions of matrices / vectors are given with initialisation functions. But while my initial matrix is set ok, the following vector (column) will not initialise. I’ve printed out the values of the variables passed into the function in case there was a problem with the test. “data type not understood” I cannot fathom
Hey @Brendon_Wolff-Piggot,
As the error suggests, indeed numpy doesn’t understand your data-type Let’s see why numpy refuses to do so. If we take a look at the documentation of np.random.randn, we will find that it takes dimensions in the form of separate arguments, i.e., if we need a (2, 3) dimensional matrix of random samples drawn from a standard normal distribution, we will use:
np.random.randn(2, 3)
However, the same format doesn’t work for numpy.zeros and numpy.ones. If we take a look at the documentation of np.zeros, we will find that the shape needs to be passed either as an integer (single dimension case) or as a tuple of integers (multiple dimension case). So, all you need to do is use np.zeros(n_h,1) and np.zeros(n_y,1) as
np.zeros((n_h,1))
np.zeros((n_y, 1))
Now, as to why numpy provides 2 different formats like this, this is primarily to support different packages, for instance Matlab. If you check out the documentation of np.random.randn(), you will find the below to be mentioned:
This is a convenience function for users porting code from Matlab, and wraps standard_normal. That function takes a tuple to specify the size of the output, which is consistent with other NumPy functions like numpy.zeros and numpy.ones.
You will find a similar thing mentioned in the docs of various other functions provided by Numpy as well. I hope this helps.
Now I pass the tests, but there is still an error stating that the shape of the first matrix is wrong. Looking at the output it seems that the matrix size parameters have somehow been incremented after the matrices were defined.
And even though the test is marked as passed the outputs do not match?
I have only one print statement and that is before the matrix / vector sizes are assigned: