all AI news
sum() and mean() in PyTorch
April 5, 2024, 10:40 p.m. | Super Kai (Kazuya Ito)
DEV Community dev.to
*My post explains min(), max(), argmin() and argmax().
sum() can get the sum values as shown below:
*Memos:
sum() 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.
import torch
my_tensor = torch.tensor([[5, 4, 7, 7],
[6, 5, 3, 5],
[3, 8, 9, 3]])
torch.sum(my_tensor)
my_tensor.sum()
# tensor(65)
torch.sum(my_tensor, 0)
my_tensor.sum(0)
torch.sum(my_tensor, (0,))
my_tensor.sum((0,))
torch.sum(my_tensor, …
dimensions functional import max mean memos pytorch sum tensor torch values
More from dev.to / DEV Community
Jobs in AI, ML, Big Data
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
Data Scientist
@ Publicis Groupe | New York City, United States
Bigdata Cloud Developer - Spark - Assistant Manager
@ State Street | Hyderabad, India