Answer the question
In order to leave comments, you need to log in
How to properly transpose matrices in numpy?
Good evening.
For educational purposes, I'm trying to write and train a neural network. And I get the following error:
ValueError: shapes (900,) and (4,) not aligned: 900 (dim 0) != 4 (dim 0)
# количество проходов по учебному набору
iteration = 10
# коэфф. обучения
alpha = 0.004
# инициация размера массива
num_pixels = 900
# инициация размера выхода
num_output = 4
# объявление весов
weight_0_1 = 0.2*np.random.random((num_pixels, num_output)) - 0.1
for j in range(iteration):
error = 0
for i in range(len(data)):
# получение входных значений для первого слоя
layer_0 = np.array(data[i][1:])
layer_0 = layer_0.astype(float)
# прямое распространение
layer_1 = np.dot(layer_0, weight_0_1)
# ошибка
error += np.sum((layer_1 - goal_set[i]) ** 2)
# обратное распространение
layer_1_delta = (goal_set[i] - layer_1)
weight_0_1 += alpha * np.dot(layer_0.T, layer_1_delta)
print(f'I:{j} Error:{error}')
Answer the question
In order to leave comments, you need to log in
As far as I understand, numpy's transpose operation does not allow you to convert a row vector to a column vector. --- ????? Where did you get this from?
a=np.array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15])
print(a)
b=a.reshape(-1,1)
print(b)
[ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question