【问题标题】:TypeError: can't multiply sequence by non-int of type 'float' numpyTypeError:不能将序列乘以“float”numpy 类型的非整数
【发布时间】: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-kFormatting posts ... Formatting help。请不要发布代码/数据/追溯的图像。只需复制文本,将其粘贴到您的问题中并将其格式化为代码即可。
  • WA的内容是什么?
  • AWdtype 是什么?您也可以在np.dot 之前assert 内部尺寸。
  • A为比特币交易数据,W为第一层激活,随机初始化值
  • 请发布一个可以重现错误的最小数据示例,...small 形状。 minimal reproducible example

标签: python numpy


【解决方案1】:

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

【讨论】:

  • 你可以删除问题。
猜你喜欢
  • 1970-01-01
  • 2010-12-30
  • 2012-10-09
  • 1970-01-01
  • 2021-10-26
  • 2017-02-04
  • 2019-03-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多