banachtarski
banachtarski

Reputation: 69

"TypeError: can't multiply sequence by non-int of type 'float'" when doing a numpy dot product

I'm currently trying to learn to code a Neural Network from scratch in python but I am stuck at the following error when trying to code the matrix "layer2_outputs". Here's my code so far:

inputs = [[1, 2, 3, 2.5],
         [2.0, 5.0, -1.0, 2.0],
         [-1.5, 2.7, 3.3, -0.8]]

weights = [[0.2, 0.8, -0.5, 1.0],
          [0.5, -0.91, 0.26, -0.5],
          [-0.26, -0.27, 0.17, 0.87]]
biases = [2, 3, 0.5]

weights2 = [[0.1, -0,14, 0.5],
           [-0.5, 0.12, -0.33],
           [-0.44, 0.73, -0.13]]
biases2 = [-1, 2, -0.5] 

layer1_outputs = np.dot(inputs, np.array(weights).T) + biases

layer2_outputs = np.dot(layer1_outputs, np.array(weights2)) + biases2

print(layer2_outputs)

I've already tried to look up the error message, but I wasn't able to find a solution to my problem, so if any of you can help me out, I'd be more than happy and in case you need any other information, just ask me, I'm new to Stack Overflow, so don't be too harsh haha :)

Here's the exact error message, in case that can help:

> VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a 
list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. 
If you meant to do this, you must specify 'dtype=object' when creating the ndarray
layer2_outputs = np.dot(layer1_outputs, np.array(weights2)) + biases2
Traceback (most recent call last):
File "c:\Users\[myName]\Desktop\firstneuralnetwork.py", line 20, in <module>
**layer2_outputs = np.dot(layer1_outputs, np.array(weights2)) + biases2**
File "<__array_function__ internals>", line 5, in dot
**TypeError: can't multiply sequence by non-int of type 'float'**

Upvotes: 0

Views: 193

Answers (1)

Sam
Sam

Reputation: 105

-0,14 should be -0.14 in weights2

The first line of the error message means you are trying to build a np array that isn't rectangular which is not allowed

Upvotes: 1

Related Questions