Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PyTorch torch.range function

PyTorch torch.range function


PyTorch torch reference manual PyTorch torch reference manual

torch.range is a function in PyTorch used to create a tensor with an arithmetic sequence 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 a step of 2

y

=

torch.

range

(

1

,

10

,

2

)

print

(

y

)


PyTorch torch reference manual PyTorch torch reference manual