【发布时间】:2019-07-28 18:58:01
【问题描述】:
我有 60000 个 784 维的向量。该数据有 10 个类别。
我必须评估一个取出一维并再次计算距离度量的函数。这个函数正在计算每个向量到它的类的平均值的距离。在代码中:
def objectiveFunc(self, X, y, indices):
subX = np.array([X[:,i] for i in indices]).T
d = np.zeros((10,1))
for n in range(10):
C = subX[np.where(y == n)]
u = np.mean(C, axis = 0)
Sinv = pinv(covariance(C))
d[n] = np.mean(np.apply_along_axis(mahalanobis, axis = 1, arr=C, v=u, VI=Sinv))
其中索引在每次迭代期间被删除一个索引。
您可以想象,在计算马氏距离的过程中,我计算了很多单独的分量。有没有办法存储所有 784 个组件的距离?
或者,计算马氏距离的最快方法是什么?
【问题讨论】:
标签: python performance distance