N
N
niklih132018-07-19 22:04:28
Python
niklih13, 2018-07-19 22:04:28

How to fix a bug in numpy calculations?

Here is the whole code:

import numpy as np

i1 = np.array();


out = [-1,1,0,1,1,1];

np.random.seed(1);

syn0 = 2*np.random.random((2,3)) - 1
syn1 = 2*np.random.random((3,1)) - 1


for iter in range(60000):

    l0 = i1;
    l1 = np.tanh(np.dot(l0,syn0));
    l2 = np.tanh(np.dot(l1,syn1));

    l2_error = out - l2;

    if (iter % 10000) == 0:
        print( "Error:" + str(np.mean(np.abs(l2_error))));

    l2_delta = l2_error*np.tanh(l2);

    l1_error = l2_delta.dot(syn1.T);

    l1_delta = l1_error * np.tanh(l1);

    syn1 += l1.T.dot(l2_delta);
    syn0 += l0.T.dot(l1_delta);


print(l2);

In the line l1_error = l2_delta.dot(syn1.T); throws an error ValueError: shapes (6,6) and (1,3) not aligned: 6 (dim 1) != 1 (dim 0)
How can I fix this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2018-07-19
@niklih13

https://stackoverflow.com/questions/39608421/showi...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question