Pairwise Euclidean distance between two matrices.
    :param A: a matrix.
    :param B: a matrix.

    :returns: A tensor for the pairwise Euclidean between A and B.

def pairwise_euclid_distance(A, B):
    """Pairwise Euclidean distance between two matrices.
    :param A: a matrix.
    :param B: a matrix.

    :returns: A tensor for the pairwise Euclidean between A and B.
    """
    batchA = tf.shape(A)[0]
    batchB = tf.shape(B)[0]

    sqr_norm_A = tf.reshape(tf.reduce_sum(tf.pow(A, 2), 1), [1, batchA])
    sqr_norm_B = tf.reshape(tf.reduce_sum(tf.pow(B, 2), 1), [batchB, 1])
    inner_prod = tf.matmul(B, A, transpose_b=True)

    tile_1 = tf.tile(sqr_norm_A, [batchB, 1])
    tile_2 = tf.tile(sqr_norm_B, [1, batchA])
    return (tile_1 + tile_2 - 2 * inner_prod)