How to define a normal distribution using tensors?
I want to define multivariate normal distribution with mean [0, 0, 0, 0] and variance - covariance matrix with only ones on diagonal. My code was:
import torch
import torch.distributions as td
td.Normal(loc=torch.tensor(np.zeros(4)), scale=torch.tensor(np.diag(np.repeat(1, 4)), dtype = float)) 

But I obtain Value Error:
ValueError: The parameter scale has invalid values

what should I do for proper definition?

torch.distributions.Normal is the univariate normal distribution.  It handles tensor arguments by computing the results as an array of univariate distributions (using broadcasting).
For example, in the following, normal implements two univariate normal distributions, one with mean 0 and std. dev 1, and the other with mean 9 and std. dev. 0.25:
In [89]: normal = td.Normal(loc=torch.tensor([0.0, 9.0]),
    ...:                    scale=torch.tensor([1, 0.25]))

Draw 5 samples from each distribution:
In [90]: normal.rsample(sample_shape=[5])
Out[90]: 
tensor([[ 0.2460,  8.6748],
        [-0.8655,  9.0666],
        [ 0.6386,  8.7980],
        [ 0.5817,  9.1428],
        [-0.1418,  8.5777]], dtype=torch.float64)

For the multivariate normal distribution, use torch.distributions.multivariate_normal.MultivariateNormal.
For example,
In [98]: mvn = td.multivariate_normal.MultivariateNormal(
    ...:     loc=torch.zeros(4, dtype=torch.float64),
    ...:     covariance_matrix=torch.eye(4, dtype=torch.float64))

In [99]: mvn.rsample([5])
Out[99]: 
tensor([[ 0.6445,  1.3138, -2.1718,  1.1653],
        [-1.7391, -1.0428,  0.3636,  0.1957],
        [ 1.9167, -0.2738, -0.1590,  0.7170],
        [ 0.0691, -0.5422,  1.8694,  0.7470],
        [ 0.3545,  1.0585, -0.1825, -1.9955]], dtype=torch.float64)

