tout dans PyTorch

Linda Hamilton
Libérer: 2024-12-31 20:15:17
original
634 Les gens l'ont consulté

all in PyTorch

Achetez-moi un café☕

*Mon message explique any().

all() peut vérifier si tous les éléments d'un tenseur 0D ou plus D sont vrais, obtenant le tenseur 0D ou plus D de zéro ou plusieurs éléments comme indiqué ci-dessous :

*Mémos :

  • all() peut être utilisé avec une torche ou un tenseur.
  • Le 1er argument (entrée) avec torch ou en utilisant un tenseur (Required-Type : tenseur de int, float, complexe ou bool).
  • Le 2ème argument avec torch ou le 1er argument avec un tenseur est dim(Optional-Type:int, tuple of int ou list of int).
  • Le 3ème argument avec torch ou le 2ème argument avec un tenseur est keepdim(Optional-Default:False-Type:bool). *Mon message explique l'argument keepdim.
  • Il y a un argument avec torch(Optional-Default:None-Type:tensor) : *Mémos :
    • out= doit être utilisé.
    • Mon message explique notre argument.
  • Un tenseur vide renvoie un Vrai d'un tenseur 1D ou plus D ou un tenseur 1D ou plus D vide.
import torch

my_tensor = torch.tensor(True)

torch.all(input=my_tensor)
my_tensor.all()
torch.all(input=my_tensor, dim=0)
torch.all(input=my_tensor, dim=-1)
torch.all(input=my_tensor, dim=(0,))
torch.all(input=my_tensor, dim=(-1,))
# tensor(True)

my_tensor = torch.tensor([True, False, True, False])

torch.all(input=my_tensor)
torch.all(input=my_tensor, dim=0)
torch.all(input=my_tensor, dim=-1)
torch.all(input=my_tensor, dim=(0,))
torch.all(input=my_tensor, dim=(-1,))
# tensor(False)

my_tensor = torch.tensor([[True, False, True, False],
                          [True, False, True, False]])
torch.all(input=my_tensor)
torch.all(input=my_tensor, dim=(0, 1))
torch.all(input=my_tensor, dim=(0, -1))
torch.all(input=my_tensor, dim=(1, 0))
torch.all(input=my_tensor, dim=(1, -2))
torch.all(input=my_tensor, dim=(-1, 0))
torch.all(input=my_tensor, dim=(-1, -2))
torch.all(input=my_tensor, dim=(-2, 1))
torch.all(input=my_tensor, dim=(-2, -1))
# tensor(False)

torch.all(input=my_tensor, dim=0)
torch.all(input=my_tensor, dim=(0,))
torch.all(input=my_tensor, dim=-2)
# tensor([True, False, True, False])

torch.all(input=my_tensor, dim=1)
torch.all(input=my_tensor, dim=-1)
torch.all(input=my_tensor, dim=(-1,))
# tensor([False, False])

my_tensor = torch.tensor([[0, 1, 2, 3],
                          [4, 5, 6, 7]])
torch.all(input=my_tensor)
# tensor(False)

my_tensor = torch.tensor([[0., 1., 2., 3.],
                          [4., 5., 6., 7.]])
torch.all(input=my_tensor)
# tensor(False)

my_tensor = torch.tensor([[0.+0.j, 1.+0.j, 2.+0.j, 3.+0.j],
                          [4.+0.j, 5.+0.j, 6.+0.j, 7.+0.j]])
torch.all(input=my_tensor)
# tensor(False)

my_tensor = torch.tensor([[]])

torch.all(input=my_tensor)
# tensor(True)

torch.all(input=my_tensor, dim=0)
torch.all(input=my_tensor, dim=-2)
# tensor([], dtype=torch.bool)

torch.all(input=my_tensor, dim=1)
torch.all(input=my_tensor, dim=-1)
# tensor([True])
Copier après la connexion

Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!

Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Derniers articles par auteur
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal