Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ValueError:python AI程序中的矩阵未对齐问题_Python_Matrix_Artificial Intelligence_Calculation_Valueerror - Fatal编程技术网

ValueError:python AI程序中的矩阵未对齐问题

ValueError:python AI程序中的矩阵未对齐问题,python,matrix,artificial-intelligence,calculation,valueerror,Python,Matrix,Artificial Intelligence,Calculation,Valueerror,我一直在尝试做一个人工智能程序,但它不起作用。我将在终端中包含错误的照片。我要做的是给它一个4位数输入的例子,然后让它组成一个公式,最后让我选择我自己的输入并尝试这个公式。谢谢大家! import numpy as np def sigmoid(x, deriv=False): if(deriv==True): return (x*(1-x)) return 1/(1+np.exp(-x)) x = np.array([[1,0,0,1]]) y = np

我一直在尝试做一个人工智能程序,但它不起作用。我将在终端中包含错误的照片。我要做的是给它一个4位数输入的例子,然后让它组成一个公式,最后让我选择我自己的输入并尝试这个公式。谢谢大家!

import numpy as np

def sigmoid(x, deriv=False):
    if(deriv==True):
        return (x*(1-x))

    return 1/(1+np.exp(-x))

x = np.array([[1,0,0,1]])

y = np.array([[1],
[2]])

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

for j in range(60000):

    l0 = x
    l1 = sigmoid(np.dot(l0, syn0))
    l2 = sigmoid(np.dot(l1, syn1))

    l2_error = y - l2
    if (j % 10000) == 0:
        print ('Error:' + str(np.mean(np.abs(l2_error))))

    l2_delta = l2_error * sigmoid(l2, deriv=True)
    l1_error = l2_delta.dot(syn1.T)
    l1_delta = l1_error * sigmoid(l1, deriv=True)

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

newX1 = int(input("x1: "))
newX2 = int(input("x2: "))
newX3 = int(input("x3: "))
newX4 = int(input("x4: "))
newX = np.array([[newX1], [newX2], [newX3], [newX4]])
l0 = newX
l1 = sigmoid(np.dot(l0, syn0))
l2 = sigmoid(np.dot(l1, syn1))
print (l2)
这是终端中的错误。它说:

line 31, in <module>
    syn0 += l0.T.dot(l1_delta)
ValueError: matrices are not aligned
第31行,在
syn0+=l0.T.dot(l1_delta)
ValueError:矩阵未对齐