PyTorch torch.range Function
Pytorch torch Reference Manual
torch.rangeIt is a function in PyTorch used to create an arithmetic sequence tensor that includes the end value.
Function Definition
torch.range(start=0, end, step=1, dtype=None, device=None, requires_grad=False)
Usage Examples
Example
import torch
# Create an arithmetic sequence from 0 to 5 (including 5)
x = torch.range(5)
print(x)
# Create an arithmetic sequence from 1 to 10 with step size 2
y = torch.range(1, 10, 2)
print(y)
# Create an arithmetic sequence from 0 to 5 (including 5)
x = torch.range(5)
print(x)
# Create an arithmetic sequence from 1 to 10 with step size 2
y = torch.range(1, 10, 2)
print(y)
Other Extensions