如何用张量的每个条目的适当等级替换张量的条目?

问题描述 投票:0回答:1

假设我有以下张量:

>> i = 3
>> j = 5
>> k = 2
>> sor = torch.randn(i,j,k)

>> sor
Out[20]: 
tensor([[[ 0.5604, -0.9675],
         [-1.0953, -0.5615],
         [ 0.4250, -0.9176],
         [-1.6188, -1.0217],
         [-0.0778,  1.9407]],

        [[-0.1034, -0.7925],
         [-0.2955,  0.8058],
         [-0.5349,  1.1040],
         [ 1.1240,  0.8249],
         [ 0.0827, -1.2471]],

        [[ 0.5924,  0.4777],
         [-2.4640, -1.9527],
         [-0.4519,  0.4788],
         [-0.2308, -0.2368],
         [-1.6786,  0.1360]]])

假设对于每个固定的ij,我想计算k上元素的数字等级,并用那些等级替换张量sor的元素。例如,在上面的示例中,由于[ 0.5604, -0.9675]

,我想将sor[0,0,:]项更改为[1, 2]

谢谢,

python tensorflow pytorch ranking tensor
1个回答
0
投票

我认为您正在寻找0.5604 > -0.9675

torch.argsort
© www.soinside.com 2019 - 2024. All rights reserved.