April 13, 2024, 10:45 p.m. | Super Kai (Kazuya Ito)

DEV Community dev.to

mean() can get the mean(average) values as shown below:


*Memos:




  • mean() can be called both from torch and a tensor.

  • The 2nd argument is one or more dimensions with torch.

  • The 1st argument is one or more dimensions with a tensor.


  • mean() can only accept floating-point or complex numbers so you need conversion to them if they are not as I explain it in my answer(17.1) otherwise there is the error.



import torch

my_tensor = torch.tensor([[5, 4, 7, 7], …

conversion dimensions function mean median memos numbers pytorch tensor them torch values

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

Business Data Scientist, gTech Ads

@ Google | Mexico City, CDMX, Mexico

Lead, Data Analytics Operations

@ Zocdoc | Pune, Maharashtra, India