【发布时间】:2016-03-31 17:26:07
【问题描述】:
总结如下:
我需要将 s(dot product) 替换为以下内容:
我的代码非常慢:
summing = 0
update = np.zeros((5172,))
for index, xi in enumerate(x_v1):
yval = y[index]
kernel_sum = 0
for index_val, x_val in enumerate(x_v1):
kernel_sum += update[index_val] *(np.dot(x_val, xi.transpose()) + 1)**2
dot_product = kernel_sum
dot_product = np.clip(dot_product, -20, 20)
summing += yval * np.log(sigmoid(dot_product)) + (1-yval)* np.log(1-sigmoid(dot_product))
我怎样才能加快速度?
【问题讨论】:
-
你看过使用
numpy.einsum吗? Here's a nice answer 解释使用它。 -
如果您的代码正在运行并且您需要一些关于如何改进它的提示,您可能希望将此类问题移至 CodeReview (codereview.stackexchange.com)