我正在尝试初始化以下NN模型:
def initialize_parameters(n_x, n_h, n_y):
W1 = np.random.randn(4,2) *0.01
b1 = np.zeros((4,1))
W2 = np.random.randn(1,4) * 0.01
b2 = np.zeros((1,1))
assert (W1.shape == (n_h, n_x))
assert (b1.shape == (n_h, 1))
assert (W2.shape == (n_y, n_h))
assert (b2.shape == (n_y, 1))
parameters = {"W1": W1,
"b1": b1,
"W2": W2,
"b2": b2}
return parameters
我的输出结果如下:
W1 = [[-0.00416758 -0.00056267]
[-0.02136196 0.01640271]
[-0.01793436 -0.00841747]
[ 0.00502881 -0.01245288]]
b1 = [[ 0.]
[ 0.]
[ 0.]
[ 0.]]
W2 = [[-0.01057952 -0.00909008 0.00551454 0.02292208]]
b2 = [[ 0.]]
正确的答案应该是:
W1 [[-0.00416758 -0.00056267] [-0.02136196 0.01640271] [-0.01793436 -0.00841747] [ 0.00502881 -0.01245288]]
b1 [[ 0.] [ 0.] [ 0.] [ 0.]]
W2 [[-0.01057952 -0.00909008 0.00551454 0.02292208]]
b2 [[ 0.]]
W1
和b1
显然是错误的,但我无法以任何其他方式使其发挥作用。新手在这里。
答案 0 :(得分:0)
它不接受,因为你硬编码所有值f.ex. np.random.randn(4,2)* 0.01中的4和2。而是使用参数n_h,n_x。