首页 > 解决方案 > Constant accepted but not defined

问题描述

Hello I have the following question.

I have code like this:

'### 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'

Now my question is, take a look at the bold layer_dims

It seems when I compile my code I have no error at all. But the strange thing is when I put layers_dim (so layer with an s) in my function I receive also no error unthough the constant is defined as layer_dims

I start receiving an error when I put in the function eg: layerss_dim (2 ss), or blablabla or layer_dimsss etc...

The error is something like: layerss_dim is not defined.

So why do I not receive an error when I use my constant as layers_dim in my function and why do I receive an error when I use the above constants like layerss_dim, blablabla, layer_dimss, etc...

In any case the constant is defined as layer_dim!

标签: python-3.x

解决方案


推荐阅读