torch.split(tensor, split_size_or_sections, dim=0)#将张量拆分为多个块。#如果split_size_or_sections是整数类型,则张量将被分成相等大小的块(如果可能)。#如果沿着给定维度dim的张量大小不能被split_size整除,则最后一个块会更小。 #如果split_size_or_sections是一个列表,则张量将根据split_size_or_sections分为len(split_size_or_sections)个块,其大小为dim。#tensor (Tensor) – tensor to split.#split_size_or_sections (int) or (list(int)) – 单个块的大小或每个块的大小列表#dim (int) – 分割张量的尺寸
torch.chunk()函数
torch.chunk(input, chunks, dim=0) → List of Tensors
#将张量拆分为特定数量的块。 #如果沿着给定维度dim的张量大小无法被块整除,则最后一个块将更小。#input (Tensor) – the tensor to split#chunks (int) – 要返回的块数#dim (int) – 分割张量的尺寸
torch.stack()函数
#将张量的序列沿新维度连接起来。 所有张量都必须具有相同的大小。#example>>> x = torch.randn(2,3)>>> torch.stack((x, x, x),0).size()
torch.Size([3,2,3])>>> torch.stack((x, x, x),1).size()
torch.Size([2,3,3])>>> torch.stack((x, x, x),2).size()
torch.Size([2,3,3])>>> torch.stack((x, x, x),3).size()
IndexError: Dimension out of range(expected to be inrange of [-3,2], but got 3)