Maison > Article > développement back-end > isclose dans PyTorch
Achetez-moi un café☕
*Mémos :
isclose() peut vérifier si zéro ou plusieurs éléments du 1er tenseur 0D ou plus D sont égaux ou presque égaux à zéro ou plusieurs éléments du 2e tenseur 0D ou plus D par élément, obtenant le 0D ou plus Tenseur D de zéro ou plusieurs éléments comme indiqué ci-dessous :
*Mémos :
import torch tensor1 = torch.tensor([1.00001001, 1.00000996, 1.00000995, torch.nan]) tensor2 = torch.tensor([1., 1., 1., torch.nan]) torch.isclose(input=tensor1, other=tensor2) torch.isclose(input=tensor1, other=tensor2, rtol=1e-05, atol=1e-08, equal_nan=False) # 0.00001 # 0.00000001 tensor1.isclose(other=tensor2) torch.isclose(input=tensor2, other=tensor1) # tensor([False, False, True, False]) torch.isclose(input=tensor1, other=tensor2, equal_nan=True) # tensor([False, False, True, True]) tensor1 = torch.tensor([[1.00001001, 1.00000996], [1.00000995, torch.nan]]) tensor2 = torch.tensor([[1., 1.], [1., torch.nan]]) torch.isclose(input=tensor1, other=tensor2) torch.isclose(input=tensor2, other=tensor1) # tensor([[False, False], # [True, False]]) tensor1 = torch.tensor([[[1.00001001], [1.00000996]], [[1.00000995], [torch.nan]]]) tensor2 = torch.tensor([[[1.], [1.]], [[1.], [torch.nan]]]) torch.isclose(input=tensor1, other=tensor2) torch.isclose(input=tensor2, other=tensor1) # tensor([[[False], [False]], # [[True], [False]]]) tensor1 = torch.tensor([[1.00001001, 1.00000996], [1.00000995, torch.nan]]) tensor2 = torch.tensor([1., 1.]) torch.isclose(input=tensor1, other=tensor2) torch.isclose(input=tensor2, other=tensor1) # tensor([[False, False], # [True, False]]) tensor1 = torch.tensor([[1.00001001, 1.00000996], [1.00000995, torch.nan]]) tensor2 = torch.tensor(1.) torch.isclose(input=tensor1, other=tensor2) torch.isclose(input=tensor2, other=tensor1) # tensor([[False, False], # [True, False]]) tensor1 = torch.tensor([0, 1, 2]) tensor2 = torch.tensor(1) torch.isclose(input=tensor1, other=tensor2) # tensor([False, True, False]) tensor1 = torch.tensor([0.+0.j, 1.+0.j, 2.+0.j]) tensor2 = torch.tensor(1.+0.j) torch.isclose(input=tensor1, other=tensor2) # tensor([False, True, False]) tensor1 = torch.tensor([False, True, False]) tensor2 = torch.tensor(True) torch.isclose(input=tensor1, other=tensor2) # tensor([False, True, False])
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!