这么久才进行了这个作业,其实只要专心地做不走神就能很快地完成作业。梯度检查很实用,需要注意的是在用dropout之前用梯度检查确保反向传播是正确的,用了dropout以后就不要梯度检查了。
把所有的theta转换成各个参数对应的:
# 向量theta分解为适用于计算的W1, b1, W2, b2, W3, b3
def vector_to_dictionary(theta):
"""
Unroll all our parameters dictionary from a single vector satisfying our specific required shape.
"""
parameters = {}
parameters["W1"] = theta[:20].reshape((5,4))
parameters["b1"] = theta[20:25].reshape((5,1))
parameters["W2"] = theta[25:40].reshape((3,5))
parameters["b2"] = theta[40:43].reshape((3,1))
parameters["W3"] = theta[43:46].reshape((1,3))
parameters["b3