def argnanmedoid(x, axis=1):
"""
Return the indices of the medoid
:param x: input array
:param axis: axis to medoid along
:return: indices of the medoid
"""
if axis == 0:
x = x.T
invalid = anynan(x, axis=0)
band, time = x.shape
diff = x.reshape(band, time, 1) - x.reshape(band, 1, time)
dist = np.sqrt(np.sum(diff * diff, axis=0)) # dist = np.linalg.norm(diff, axis=0) is slower somehow...
dist_sum = nansum(dist, axis=0)
dist_sum[invalid] = np.inf
i = np.argmin(dist_sum)
return i
评论列表
文章目录