TypeError:无法将序列乘以'float'numpy类型的非整数

时间:2018-08-24 13:11:22

标签: python numpy

当我将正确尺寸的numpy数组传递给下面的函数时,出现错误:TypeError:无法将序列乘以'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

1 个答案:

答案 0 :(得分:0)

发现了问题。数据集中有字符串。