PyTorch Create a tensor with random values

Below is the code to create a tensor with random values in PyTorch

rand_tensor = torch.rand([3, 2])

Complete file code to test that:

import torch

rand_tensor = torch.rand([3, 2])

print(rand_tensor)

Output:

tensor([[0.3042, 0.2289],
        [0.2549, 0.7466],
        [0.7153, 0.2489]])

In the above code, we created a two-dimensional (three rows and two columns) tensor populated with random data.