squared_euclidean_distances = (X ** 2).sum(1).reshape((X.shape[0], 1)) + (Y **
    2).sum(1).reshape((1, Y.shape[0])) - 2 * X.dot(Y.T)
f_euclidean = theano.function([X, Y], T.sqrt(squared_euclidean_distances))
pdist for theano tensor