当我将正确维度的numpy数组传递给下面的函数时,我得到一个错误:类型错误:不能将序列乘以类型为"float"的非整数。 见图
请帮忙。
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
数据:示例数据集
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
发现问题。数据集中有字符串。