YouTip LogoYouTip

Pytorch Torch Cartesian_Prod

# PyTorch torch.cartesian_prod Function * * PyTorch torch Reference Manual](#) `torch.cartesian_prod` is a function in PyTorch used to calculate the Cartesian product. It returns the Cartesian product of input tensors, which is the set of all possible combinations. ### Function Definition torch.cartesian_prod(*tensors) * * * ## Usage Examples ## Example import torch # Compute the Cartesian product of two tensors a = torch.tensor([1,2,3]) b = torch.tensor([4,5]) result = torch.cartesian_prod(a, b) print("a:", a) print("b:", b) print("Cartesian product:") print(result) # tensor([[1, 4], # [1, 5], # [2, 4], # [2, 5], # [3, 4], # [3, 5]]) # Cartesian product of multiple tensors x = torch.tensor([1,2]) y = torch.tensor([10,20,30]) z = torch.tensor([100,200]) result = torch.cartesian_prod(x, y, z) print("Three-tensor Cartesian product shape:", result.shape) print(result) * * PyTorch torch Reference Manual](#)
← Tag TemplatePytorch Torch Bucketize β†’