torch.vsplit¶
- torch.vsplit(input, indices_or_sections) 張量列表¶
根據
indices_or_sections垂直地將具有兩個或更多維度的張量input拆分成多個張量。每個拆分都是input的檢視。這等效於呼叫 torch.tensor_split(input, indices_or_sections, dim=0)(拆分維度是 0),但如果
indices_or_sections是一個整數,則它必須能夠整除拆分維度,否則將丟擲執行時錯誤。此函式基於 NumPy 的
numpy.vsplit()。- 引數
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.vsplit(t, 2) (tensor([[0., 1., 2., 3.], [4., 5., 6., 7.]]), tensor([[ 8., 9., 10., 11.], [12., 13., 14., 15.]])) >>> torch.vsplit(t, [3, 6]) (tensor([[ 0., 1., 2., 3.], [ 4., 5., 6., 7.], [ 8., 9., 10., 11.]]), tensor([[12., 13., 14., 15.]]), tensor([], size=(0, 4)))