python-3.x - 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!
解决方案
推荐阅读
- tableau-api - Tableau - 多个标准的最新记录
- c# - 为什么 Xaml 在运行时反序列化 - 而不是在编译时?
- excel - 使用 VBA 切换 Excel 功能区
- docker - 如何安装 32 位 docker 容器
- android - Android Google Play Services-Vision 源码
- javascript - 如何将 GLSL 文件与 Gulp 捆绑在一起?
- linux - 如何在 Bash 中对字母数字字符串进行排序
- php - 无法使用 SquareConnect 创建变体
- sql - SQLPLUS SPOOL - NUMBER 字段上的 TO_CHAR 添加尾随空格
- mysql - MySQL WHERE IN(字符串的子字符串)?