【发布时间】:2018-08-24 13:11:22
【问题描述】:
当我将正确维度的 numpy 数组传递给下面的函数时,我收到一个错误:TypeError: can't multiply sequence by non-int of type 'float'。
see picture
请帮忙。
def linear_forward(A, W, b):
print('W.type:', type(W), 'W.shape:', W.shape)
print('A.type:', type(A), 'A.shape:', A.shape)
Z = np.dot(W, A) + b
assert (Z.shape == (W.shape[0], A.shape[1]))
cache = (A, W, b)
return Z, cache
一条数据:sample dataset
这里的代码生成W(等于参数['W1']):
@staticmethod
def initialize_parameters(layer_dimensions):
"""
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)
"""
parameters = {}
L = len(layer_dimensions) # number of layers in the network
for l in range(1, L):
parameters['W' + str(l)] = np.random.randn(layer_dimensions[l], layer_dimensions[l - 1]) * 0.01
parameters['b' + str(l)] = np.zeros((layer_dimensions[l], 1))
assert (parameters['W' + str(l)].shape == (layer_dimensions[l], layer_dimensions[l - 1]))
assert (parameters['b' + str(l)].shape == (layer_dimensions[l], 1))
return parameters
[1]: https://i.stack.imgur.com/rXXT3.png
[2]: https://drive.google.com/file/d/18teb1vrVbCnPzG_eFClTiLRm6VTjCNrv/view?usp=sharing
【问题讨论】:
-
请格式化代码:选择它并输入
ctrl-k。 Formatting posts ... Formatting help。请不要发布代码/数据/追溯的图像。只需复制文本,将其粘贴到您的问题中并将其格式化为代码即可。 -
W和A的内容是什么? -
A和W的dtype是什么?您也可以在np.dot之前assert内部尺寸。 -
A为比特币交易数据,W为第一层激活,随机初始化值
-
请发布一个可以重现错误的最小数据示例,...small 形状。 minimal reproducible example