我正在尝试在同一矩阵之间进行点积运算,因此发生以下错误: ValueError:操作数不能与形状(101,2)(101,)一起广播。
显然,这至少对我来说没有多大意义,因为我正在相同的两个矩阵之间进行点积运算。
def RidgeRegression(X, t, theta, alpha, T, ridgeCoef):
vtheta = np.zeros([T,2,1])
N = len(t) # number of training examples
error = np.zeros(T)
batch = 0
for it in range(T):
for numBatch in range(4):
y = np.dot(X[batch:batch+101], theta) - t[batch:batch+101]
grad = 1/2*np.dot(X[batch:batch+101].T,y)+
np.dot(X[batch:batch+101].T, X[batch:batch+101])
theta = theta - (alpha/101) * grad
batch +=101
error[it] = sum(np.dot(X, theta) - t)/N
vtheta[it,:] = theta.reshape(2,1)
batch = 0
return vtheta, error
grad = 1/2*np.dot(X[batch:batch+101].T,y) +
np.dot(X[batch:batch+101].T, X[batch:batch+101])
出现点积错误的地方。
ValueError:操作数不能与形状(101,2)(101,)一起广播
错误