Building cosine distance matrix for kmedoid