April 10, 2024, 8:27 p.m. | Super Kai (Kazuya Ito)

DEV Community dev.to

arange() can create the 1D tensor of zero or more integers or floating-point numbers as shown below:


*Memos:




  • arange() can be used only from torch but not from a tensor.

  • The 1st argument is start which is 0 by default.

  • The 2nd argument is end.

  • The 3rd argument is step which is 1 by default.

  • Setting only one argument sets 0 to start.

  • There is range() which is similar to arange() but range() is deprecated.



import torch

torch.arange(5)
# tensor([0, …

integers logspace memos normal numbers pytorch tensor torch

Data Architect

@ University of Texas at Austin | Austin, TX

Data ETL Engineer

@ University of Texas at Austin | Austin, TX

Lead GNSS Data Scientist

@ Lurra Systems | Melbourne

Senior Machine Learning Engineer (MLOps)

@ Promaton | Remote, Europe

Risk Management - Machine Learning and Model Delivery Services, Product Associate - Senior Associate-

@ JPMorgan Chase & Co. | Wilmington, DE, United States

Senior ML Engineer (Speech/ASR)

@ ObserveAI | Bengaluru