def medoid_indices(arr, invalid=None):
"""
The indices of the medoid.
:arg arr: input array
:arg invalid: mask for invalid data containing NaNs
"""
# vectorized version of `argnanmedoid`
bands, times, ys, xs = arr.shape
diff = (arr.reshape(bands, times, 1, ys, xs) -
arr.reshape(bands, 1, times, ys, xs))
dist = np.linalg.norm(diff, axis=0)
dist_sum = nansum(dist, axis=0)
if invalid is None:
# compute it in case it's not already available
invalid = anynan(arr, axis=0)
dist_sum[invalid] = np.inf
return np.argmin(dist_sum, axis=0)
评论列表
文章目录