我点积2个numpy数组,一个数组的尺寸为(150,4),另一个数组的尺寸为(4,1)。这应该导致尺寸为(150,1)的数组,但是,我得到的是(150,4)的数组。
我尝试创建数据列表列表,并将其传递给数组构造函数。
x = iris.data #shape (150, 4)
y = np.array(y_actual) #shape (150, 1)
np.random.seed(1)
syn1 = 2 * np.random.random( (x.shape[1], x.shape[1]) ) - 1
syn2 = 2 * np.random.random( (x.shape[1], y.shape[1]) ) - 1
for i in range(10000):
layer0 = x
layer1 = sigmoid( np.dot(layer0, syn1) )
layer2 = sigmoid( np.dot(layer1, syn2) )
l2_err = layer2 - y
l2_delta = l2_err * sigmoid(layer2, deriv = True)
l1_err = np.dot(l2_delta, syn2.T)
l1_delta = l1_err * sigmoid(layer1, deriv = True)
我希望layer2的尺寸为(150,1),但是我收到的尺寸为(150,4)。
答案 0 :(得分:0)
我添加了尺寸-尽我所能推论:
x = iris.data #shape (150, 4)
y = np.array(y_actual) #shape (150, 1)
np.random.seed(1)
syn1 = 2 * np.random.random( (x.shape[1], x.shape[1]) ) - 1 # (4,4)
syn2 = 2 * np.random.random( (x.shape[1], y.shape[1]) ) - 1 # (4,1)
for i in range(10000):
layer0 = x
layer1 = sigmoid( np.dot(layer0, syn1) ) # (150,4) dot (4,4)=>(150,4)
layer2 = sigmoid( np.dot(layer1, syn2) ) # (150,4) dot (4,1)=>(150,1)
l2_err = layer2 - y # (150,1) (150,1) => (150,1)
l2_delta = l2_err * sigmoid(layer2, deriv = True)
l1_err = np.dot(l2_delta, syn2.T) # (150,1) (1,4) => (150,4)
l1_delta = l1_err * sigmoid(layer1, deriv = True)