Have two tensors like:
tensor([ 5, 27]
tensor([ 1, 20,3].
I need to get this tensor:
tensor([[ 5, 1], [5,20], [5,3], [ 27, 1], [27,20], [27,3]]
How i can do it without loop!?
Have two tensors like:
tensor([ 5, 27]
tensor([ 1, 20,3].
I need to get this tensor:
tensor([[ 5, 1], [5,20], [5,3], [ 27, 1], [27,20], [27,3]]
How i can do it without loop!?
Hi,
This will do the trick and as it is the builtin function, it is the most efficient way!:
x = torch.tensor([5, 27])
y = torch.tensor([1, 20, 3])
torch.cartesian_prod(x, y)
For more info, visit official docs.
Bests