Fonction torch.numel de PyTorch
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))
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
Autres extensions