What is torch arrange

This recipe explains what is torch arrange

Recipe Objective

What is torch.arrange?

This is written as torch.arange(start=0, end, step=1, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) in which:
-- start - This will be the starting value of the set points.
-- end - these are the ending values of set points.
-- step - This is the gap between each pair of the adjacent points which is default it is 1.
-- out - This will be the output tensor.
-- dtype - This will be the data type of the returned tensor which is optional.
-- layout - This is the desired layout of the output tensor. By default it is strided
-- device - This is the desired device of the returned tensor, by default if it is None then it uses the current device for the default tensor type.
-- requires_grad - On the returned tensor if the autograd should record operations. By default it is False. The torch.arange() function will return the 1 dimensional tensor which will be of size (end - start / stop) with values from the interval [start, end] taken with common difference step beginning from start.

Step 1 - Import library

import torch

Step 2 - Apply arange

print("This is with single digit:",torch.arange(10))
print("This is with dual digit:",torch.arange(2,5))
print("This is with multiple digit:",torch.arange(1, 3.5, 0.5))

This is with single digit: tensor([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
This is with dual digit: tensor([2, 3, 4])
This is with multiple digit: tensor([1.0000, 1.5000, 2.0000, 2.5000, 3.0000])

What Users are saying..

profile image

Jingwei Li

Graduate Research assistance at Stony Brook University
linkedin profile url

ProjectPro is an awesome platform that helps me learn much hands-on industrial experience with a step-by-step walkthrough of projects. There are two primary paths to learn: Data Science and Big Data.... Read More

Relevant Projects

Text Classification with Transformers-RoBERTa and XLNet Model
In this machine learning project, you will learn how to load, fine tune and evaluate various transformer models for text classification tasks.

FEAST Feature Store Example for Scaling Machine Learning
FEAST Feature Store Example- Learn to use FEAST Feature Store to manage, store, and discover features for customer churn prediction machine learning project.

Build a Autoregressive and Moving Average Time Series Model
In this time series project, you will learn to build Autoregressive and Moving Average Time Series Models to forecast future readings, optimize performance, and harness the power of predictive analytics for sensor data.

Build a Churn Prediction Model using Ensemble Learning
Learn how to build ensemble machine learning models like Random Forest, Adaboost, and Gradient Boosting for Customer Churn Prediction using Python

Topic modelling using Kmeans clustering to group customer reviews
In this Kmeans clustering machine learning project, you will perform topic modelling in order to group customer reviews based on recurring patterns.

Loan Default Prediction Project using Explainable AI ML Models
Loan Default Prediction Project that employs sophisticated machine learning models, such as XGBoost and Random Forest and delves deep into the realm of Explainable AI, ensuring every prediction is transparent and understandable.

NLP Project to Build a Resume Parser in Python using Spacy
Use the popular Spacy NLP python library for OCR and text classification to build a Resume Parser in Python.

Machine Learning project for Retail Price Optimization
In this machine learning pricing project, we implement a retail price optimization algorithm using regression trees. This is one of the first steps to building a dynamic pricing model.

Time Series Analysis with Facebook Prophet Python and Cesium
Time Series Analysis Project - Use the Facebook Prophet and Cesium Open Source Library for Time Series Forecasting in Python

Detectron2 Object Detection and Segmentation Example Python
Object Detection using Detectron2 - Build a Dectectron2 model to detect the zones and inhibitions in antibiogram images.