PyTorch is an open-source machine learning library developed by Facebook. It is used for deep neural network and natural language processing purposes.
The function torch.range() returns a 1-D tensor of size ![]()
with values from start to end with step step. Step is the gap between two values in the tensor.
![]()
This function is deprecated in favor of torch.arange().
Syntax: torch.range(start=0, end, step=1, out=None)
Parameters:
start: the starting value for the set of points. Default: 0.
end: the ending value for the set of points
step: the gap between each pair of adjacent points. Default: 1.
out(Tensor, optional): the output tensorReturn type: A tensor
Code #1:
# Importing the PyTorch library import torch # Applying the range function and # storing the resulting tensor in 't' a = torch.range(1, 6) print("a = ", a) b = torch.range(1, 5, 0.5) print("b = ", b) |
Output:
a = tensor([1., 2., 3., 4., 5., 6.]) b = tensor([1.0000, 1.5000, 2.0000, 2.5000, 3.0000, 3.5000, 4.0000, 4.5000, 5.0000])
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
Recommended Posts:
- Python | PyTorch sin() method
- Python | PyTorch sinh() method
- Python | PyTorch cosh() method
- Python | PyTorch tanh() method
- Python | PyTorch cos() method
- Python | PyTorch tan() method
- Python | PyTorch asin() method
- Python | PyTorch acos() method
- Python | PyTorch atan() method
- Python PyTorch zeros() method
- Python Pytorch ones() method
- Python Pytorch arange() method
- Python Pytorch linspace() method
- Python Pytorch logspace() method
- Python Pytorch eye() method
- Python Pytorch empty() method
- Python Pytorch full() method
- Python - PyTorch floor() method
- Python - PyTorch fmod() method
- Python - PyTorch log() method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

