Fonction torch.numel de PyTorch


Pytorch torch 参考手册Manuel de référence PyTorch torch

torch.numelest une fonction de PyTorch utilisée pour calculer le nombre total d'éléments dans un tenseur.

Définition de fonction

torch.numel(input)

Exemples d'utilisation

Exemple

import torch

x = torch.randn(3, 4, 5)
print("Nombre total d'éléments :", torch.numel(x))

y = torch.tensor([1, 2, 3, 4, 5])
print("Nombre total d'éléments :", torch.numel(y))

Le résultat de sortie est:

元素总数: 60
元素总数: 5

Pytorch torch 参考手册Manuel de référence PyTorch torch

Autres extensions