Hi, I have this task in my hands where I have two tensors of the same two-dimensional size, let’s say tensor a
and tensor b
. I’d like to sort a and b (in the first dimension) so that the largest element of tensor b
is multiplied by the largest element of tensor a
, and the second largest element of tensor b
is multiplied by the second largest element of tensor a
, and so on. However, I want to do this by keeping the original ordering of tensor a
.
For example,
a = torch.tensor([[1,0,2], [1,2,0]])
b = torch.tensor([[0.5, 0.8, 0.1], [0.3, 0.2, 0.1]])
Take a look at the first row of tensors a and b, I want 0.8 from tensor b to be mapped with value 2 from tensor a, 0.5 with the value of 1, and 0.1 with the value of 0. Similarly, for the second row, I’d like to map 0.3 to the value of 2, 0.2 to the value of 1, and 0.1 to the value of 0.
a = torch.tensor([[1,0,2], [1,2,0]])
rearranged_b = torch.tensor([[0.5, 0.1, 0.8], [0.2, 0.3, 0.1]])
wanted_tensor = a * b
Is there a way of performing this calculation?