Pytorch разбивает массив по списку индексовPython

Программы на Python
Гость
Pytorch разбивает массив по списку индексов

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


I want to split a torch array by a list of indices.

For example say my input array is torch.arange(20)

tensor([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) and my list of indices is splits = [1,2,5,10]

Then my result would be:

(tensor([0]), tensor([1, 2]), tensor([3, 4, 5, 6, 7]), tensor([ 8, 9, 10, 11, 12, 13, 14, 15, 16, 17])) assume my input array is always long enough to bigger than the sum of my list of indices.


Источник: https://stackoverflow.com/questions/781 ... of-indices

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