You are on page 1of 2

Torch library Documentation

1. torch.rand:-

torch.rand (*size, out=None, dtype=None, layout=torch.strided, device=None, r


equires_grad=False) → Tensor

Returns a tensor filled with random numbers from a uniform distribution on the
interval [0, 1)

The shape of the tensor is defined by the variable argument size .

>>> torch.rand(4)
tensor([ 0.5204, 0.2503, 0.3525, 0.5673])
>>> torch.rand(2, 3)
tensor([[ 0.8237, 0.5781, 0.6879],
[ 0.3816, 0.7249, 0.0998]])

2. torch.rand_like:-

torch.rand_like (input, dtype=None, layout=None, device=None, requires_grad=


False) → Tensor

Returns a tensor with the same size as input that is filled with random numbers from
a uniform distribution on the interval [0, 1). torch.rand_like(input) is equivalent
to torch.rand(input.size(), dtype=input.dtype, layout=input.layout, device=inpu
t.device)

3. torch.randint:-

torch.randint (low=0, high, size, out=None, dtype=None, layout=torch.strided,


device=None, requires_grad=False) → Tensor

Returns a tensor filled with random integers generated uniformly


between low (inclusive) and high (exclusive).

The shape of the tensor is defined by the variable argument size.

>>> torch.randint(3, 5, (3,))


tensor([4, 3, 4])
4.

You might also like