import torch


def euclidean_distances(X, Y, squared=False):
    """
    Considering the rows of X (and Y=X) as vectors, compute the
    distance matrix between each pair of vectors.
    Parameters
    ----------
    X : {tensor-like}, shape (n_samples_1, n_features)
    Y : {tensor-like}, shape (n_samples_2, n_features)
    squared : boolean, optional
        Return squared Euclidean distances.
    Returns
    -------
    distances : {Tensor}, shape (n_samples_1, n_samples_2)
    """

    

    X_col = X.unsqueeze(1)
    Y_lin = Y.unsqueeze(0)
 
    if squared == True:
        c = torch.sum((torch.abs(X_col - Y_lin)) ** 2, 2).sqrt_()
    else:
        c = torch.sum((torch.abs(X_col - Y_lin)) ** 2, 2)
    

    return c