(x, cluster_centers)
return torch.clamp(distances, min=0)
Compute squared distances of samples to cluster centers.

        Parameters
        ----------
        x : torch.tensor
            Tensor of shape `(n_samples, n_features)`.

        cluster_centers : torch.tensor
            Tensor of shape `(n_clusters, n_features)`.

        Returns
        -------
        distances : torch.tensor
            Tensor of shape `(n_samples, n_clusters)` that provides for each sample (row) the squared distance
            to a given cluster center (column).
Compute squared distances of samples to cluster centers.
Compute squared distances of samples to cluster centers .
def compute_distances(x, cluster_centers):
        """Compute squared distances of samples to cluster centers.

        Parameters
        ----------
        x : torch.tensor
            Tensor of shape `(n_samples, n_features)`.

        cluster_centers : torch.tensor
            Tensor of shape `(n_clusters, n_features)`.

        Returns
        -------
        distances : torch.tensor
            Tensor of shape `(n_samples, n_clusters)` that provides for each sample (row) the squared distance
            to a given cluster center (column).

        """
        x_n = (x ** 2).sum(dim=1).view(-1, 1)  # (n_samples, 1)
        c_n = (cluster_centers ** 2).sum(dim=1).view(1, -1)  # (1, n_clusters)

        distances = x_n + c_n - 2 * torch.mm(x, cluster_centers.permute(1, 0))  # (n_samples, n_clusters)

        return torch.clamp(distances, min=0)
def compute_distances ( x , cluster_centers ) : x_n = ( x ** 2 ) . sum ( dim = 1 ) . view ( - 1 , 1 ) # (n_samples, 1) c_n = ( cluster_centers ** 2 ) . sum ( dim = 1 ) . view ( 1 , - 1 ) # (1, n_clusters) distances = x_n + c_n - 2 * torch . mm ( x , cluster_centers . permute ( 1 , 0 ) ) # (n_samples, n_clusters) return torch . clamp ( distances , min = 0 )