# Gaussian Tensor Generation

Hi,
How can I have an (n,1) gaussian tensor in PyTorch with the largest value in the middle (mean of the gaussian) and all entries normalized to be between (0,1)?

If you would like to create a Gaussian window (not sample from the Gaussian distribution), you could use e.g. `scipy.signal.gaussian` to create the values and transform it to a tensor via `torch.from_numpy(signal)`.

Thanks for the reply. Actually, I have a tensor like (B,C,H,W) and I want to multiply the last two dimensions with a gaussian (H and W are the spatial dimensions. So it’s like an attention on the middle pixels). I want it to be fully implemented in Pytorch to be able to do backpropagation.

Hi M!

If your two-dimensional (HxW) Gaussian window is going to be fixed,
i.e., something like `[1.0, 2.0, 1.0]` (in 1-d) that doesn’t depend on the
values in the tensor you want to multiply it with, then where those fixed
values came from won’t affect back-propagation. So `from_numpy (...)`
will be fine.

The point is that in back-propagation you won’t be differentiating
with respect to the constants in your Gaussian window; you’ll be
differentiating with respect to variables (elements of tensors that
have `requires_grad = True`) that those constants multiply.

Best.

K. Frank