您好我有以下问题。
我有这样的代码:
'### CONSTANTS ###'
'**layer_dims** = [12288, 20, 7, 5, 1] # 4-layer model'
'def initialize_parameters_deep(**layer_dims**):
"""
Arguments:
layer_dims -- python array (list) containing the dimensions of each layer in our network
Returns:
parameters -- python dictionary containing your parameters "W1", "b1", ..., "WL", "bL":
Wl -- weight matrix of shape (layer_dims[l], layer_dims[l-1])
bl -- bias vector of shape (layer_dims[l], 1)
"""
np.random.seed(1)
parameters = {}
L = len(layer_dims) # number of layers in the network
for l in range(1, L):
parameters['W' + str(l)] = np.random.randn(layer_dims[l], layer_dims[l-1]) / np.sqrt(layer_dims[l-1]) #*0.01
parameters['b' + str(l)] = np.zeros((layer_dims[l], 1))
assert(parameters['W' + str(l)].shape == (layer_dims[l], layer_dims[l-1]))
assert(parameters['b' + str(l)].shape == (layer_dims[l], 1))
return parameters'
现在我的问题是,看一下粗体layer_dims
似乎在编译代码时,我根本没有错误。
但奇怪的是当我在我的函数中放置layers_dim
(所以带有s的图层)时我也收到了没有错误,但常量被定义为layer_dims
当我输入函数时,我开始收到错误,例如:layerss_dim(2 ss),或blablabla或layer_dimsss等......
错误类似于:layerss_dim is not defined
。
那么为什么我在函数中使用常量layers_dim
时没有收到错误,为什么在使用上面的常量(如layerss_dim,blablabla,layer_dimss等等)时会收到错误?< / p>
在任何情况下,常量都定义为layer_dim!