Python - Liste mit arrays der Form Fragen

Ich bin momentan dabei, einen code zum ausführen eines perceptron-Algorithmus, und ich kann nicht erstellen Sie eine zufällige matrix die Art, wie ich es brauche:

from random import choice
from numpy import array, dot, random
unit_step = lambda x: -1 if x < 0 else 1
import numpy as np
m=3 #this will be the number of rows
allys=[]
for j in range(m):
    aa=np.random.rand(1,3)
    tt=np.random.rand(3)
    yy=dot(aa,tt)
    ally = [aa, yy]
    allys.append(ally)
print  "allys", allys

w = random.rand(3)
errors = []
eta = 0.2
n = 10
x=[1,3]

for i in xrange(n):
    print i 
    x, expected = choice(allys)
    print "x", x

Bekommen und habe das problem hier:

    result = dot(x,w)    
    error = expected - unit_step(result) 
    errors.append(error) 
    w += eta * error * x 
    print x, expected, w, error, result, errors

Sagt der log

w += eta * Fehler * x
ValueError: nicht-broadcastable output-Operanden-Form (3,) nicht
match-broadcast-Form (1,3)

Die Idee ist es, Ergebnis looping nach dem Zufallsprinzip über die "Tabelle" allys.

Wie kann ich dieses Problem lösen? Was ist die Form(3,)?

Dank!

  • Was sind die "allys"?
InformationsquelleAutor GabyLP | 2014-08-13
Schreibe einen Kommentar