快捷鍵

torch.vsplit

torch.vsplit(input, indices_or_sections) 張量 List

根據 indices_or_sections 將具有兩個或多個維度的張量 input 垂直分割成多個張量。每個分割都是 input 的檢視。

這等效於呼叫 torch.tensor_split(input, indices_or_sections, dim=0) (分割維度為 0),但如果 indices_or_sections 是一個整數,它必須平均劃分分割維度,否則會拋出執行階段錯誤。

此函數基於 NumPy 的 numpy.vsplit()

參數
範例:
>>> 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)))

文件

存取 PyTorch 的完整開發者文件

檢視文件

教學

取得適合初學者和進階開發者的深入教學課程

檢視教學

資源

尋找開發資源並取得問題解答

檢視資源