torch.hsplit#
- torch.hsplit(input, indices_or_sections) List of Tensors#
根據
indices_or_sections將input(一個或多個維度的張量)水平分割成多個張量。每個分割都是input的一個檢視。如果
input是一個維度,這等同於呼叫 torch.tensor_split(input, indices_or_sections, dim=0)(分割維度為零),如果input有兩個或多個維度,則等同於呼叫 torch.tensor_split(input, indices_or_sections, dim=1)(分割維度為 1),不同之處在於,如果indices_or_sections是一個整數,它必須能被分割維度整除,否則將丟擲執行時錯誤。此函式基於 NumPy 的
numpy.hsplit()。- 引數
input (Tensor) – 要分割的張量。
indices_or_sections (int 或 list 或 tuple of ints) – 請參閱
torch.tensor_split()中的引數。
示例
>>> t = torch.arange(16.0).reshape(4,4) >>> t tensor([[ 0., 1., 2., 3.], [ 4., 5., 6., 7.], [ 8., 9., 10., 11.], [12., 13., 14., 15.]]) >>> torch.hsplit(t, 2) (tensor([[ 0., 1.], [ 4., 5.], [ 8., 9.], [12., 13.]]), tensor([[ 2., 3.], [ 6., 7.], [10., 11.], [14., 15.]])) >>> torch.hsplit(t, [3, 6]) (tensor([[ 0., 1., 2.], [ 4., 5., 6.], [ 8., 9., 10.], [12., 13., 14.]]), tensor([[ 3.], [ 7.], [11.], [15.]]), tensor([], size=(4, 0)))