Maison > développement back-end > Tutoriel Python > n'importe lequel dans PyTorch

n'importe lequel dans PyTorch

Mary-Kate Olsen
Libérer: 2025-01-01 09:14:11
original
563 Les gens l'ont consulté

any in PyTorch

Achetez-moi un café☕

*Mon message explique tout().

any() peut vérifier si des é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 :

  • any() 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 False d'un tenseur 1D ou plus D ou un tenseur 1D ou plus D vide.
import torch

my_tensor = torch.tensor(True)

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

torch.any(input=my_tensor, dim=0, keepdim=True)
# tensor(True)

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

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

torch.any(input=my_tensor, dim=0, keepdim=True)
# tensor([True])

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

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

torch.any(input=my_tensor, dim=1)
torch.any(input=my_tensor, dim=-1)
torch.any(input=my_tensor, dim=(-1,))
# tensor([True, True])

torch.any(input=my_tensor, dim=0, keepdim=True)
# tensor([[True, False, True, False]])

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

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

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.any(input=my_tensor)
# tensor(True)

my_tensor = torch.tensor([[]])

torch.any(input=my_tensor)
# tensor(False)

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

torch.any(input=my_tensor, dim=1)
torch.any(input=my_tensor, dim=-1)
# tensor([False])
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