The rand function may be used to generate a tensor of a given shape and configuration, populated with random values
const a = torch.rand(1, 5);
const a = torch.rand([1, 5]);
const a = torch.rand([1, 5], {
dtype: torch.float64,
});
The tensor function may be used to create a tensor given an array of values that the tensor would consist of.
const a = torch.tensor([
[0.1, 0.2, 0.3],
[0.4, 0.5, 0.6],
]);
const a = torch.tensor(
[
[0.1, 0.2, 0.3],
[0.4, 0.5, 0.6],
],
{
dtype: torch.float64,
}
);