Как эффективно сопоставить один тензор с другим с помощью отношений один-ко-множеству в PyTorch?Python

Программы на Python
Гость
Как эффективно сопоставить один тензор с другим с помощью отношений один-ко-множеству в PyTorch?

Сообщение Гость »


Suppose I have a tensor input and an irregular 2d array mapping where mapping contains the list of indices of output that input should be mapped to, how to obtain tensor output such that output[j] equals to the sum of all the entries in input that is mapped to it, without looping? input and output are of different sizes.

For example:
input = [0,1,2,3]
mapping = [[1], [0,2,4], [0,3], [1,2]]
output = [1+2, 0+3, 1+3, 2, 1] = [3,3,4,2,1]


Источник: https://stackoverflow.com/questions/780 ... tions-in-p

Вернуться в «Python»