0

When I pass to numpy arrays of correct dimensions to the function below I get an error: TypeError: can't multiply sequence by non-int of type 'float'. see picture
Please help.

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

A data: sample dataset

W is generated by code here(its equal to parameters['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
Myron
  • 15
  • 1
  • 7
  • Please format the code: select it and type `ctrl-k`. [Formatting posts](https://stackoverflow.com/help/formatting) ... [Formatting help](https://stackoverflow.com/editing-help). Please don't post images of code/data/Tracebacks. Just copy the text, paste it in your question and format it as code. – wwii Aug 24 '18 at 13:13
  • What's the content of `W` and `A`? – Daniel Aug 24 '18 at 13:15
  • What is the `dtype` of `A` and `W`? You may also `assert` the inner dimensions before you `np.dot`. – tafaust Aug 24 '18 at 13:16
  • A is bitcoin trading data, W is activation for the first layer, randomly initialized values – Myron Aug 24 '18 at 13:18
  • Please post a minimal example of the data that will reproduce the error, .... *small* shapes. [mcve] – wwii Aug 24 '18 at 13:19
  • Possible duplicate of [Why do I get TypeError: can't multiply sequence by non-int of type 'float'?](https://stackoverflow.com/questions/485789/why-do-i-get-typeerror-cant-multiply-sequence-by-non-int-of-type-float) – tafaust Aug 24 '18 at 13:20

1 Answers1

0

Found the problem. There were strings in dataset.

Myron
  • 15
  • 1
  • 7