Computing the input to a Gaussian Kernel in pytorch in a vecotrized way (i.e. ||x-w||^2)

Does anyone know how to translate a vectorized version of ||x - w||^2 in pytorch? I have a working version in numpy but it seems there are issue with summing over axis in pytorch so I’m not sure how to translate my code to pytorch:

WW = np.sum(np.multiply(W,W), axis=0, dtype=None, keepdims=True)
XX = np.sum(np.multiply(x,x), axis=1, dtype=None, keepdims=True)
Delta_tilde = 2.0*np.dot(x,W) - (WW + XX)

e.g.

WW = (W * W).sum(axis=0, keepdim=True)

Assuming batched, (x - w).pow(2).sum(1, keepdim=True)

whats assuming batched?

I was assuming that w and x are vectors in mini-batches with the first dimension (dim 0) being the batch dimension.

w is the centers (of potentially an RBF), so W might not be the same size as a batch size. Its just like the number of filters for a fully connected network.

Hi @Brando_Miranda, you solved this question? I’ve the same doubts… I’d like to see a more detailed example than those offered here.

Im just using the original code I posted in my question but translated to pytorch.

I’ve trained a model like this: