latest (dev)
Copy
Latest development documentation · Updated 2026-10-15
tensorplay.functional.chunk
- tensorplay.functional.chunk(input: Tensor, chunks: int, dim: int = 0) Tuple[Tensor, ...][source]
Attempts to split a tensor into the specified number of chunks. Each chunk is a view of the input tensor.
Note
This function may return fewer than the specified number of chunks!
See also
tensorplay.tensor_split()a function that always returns exactly the specified number of chunksIf the tensor size along the given dimension
dimis divisible bychunks, all returned chunks will be the same size. If the tensor size along the given dimensiondimis not divisible bychunks, all returned chunks will be the same size, except the last one. If such division is not possible, this function may return fewer than the specified number of chunks.- Parameters:
Example
>>> tensorplay.arange(11).chunk(6) (tensor([0, 1]), tensor([2, 3]), tensor([4, 5]), tensor([6, 7]), tensor([8, 9]), tensor([10])) >>> tensorplay.arange(12).chunk(6) (tensor([0, 1]), tensor([2, 3]), tensor([4, 5]), tensor([6, 7]), tensor([8, 9]), tensor([10, 11])) >>> tensorplay.arange(13).chunk(6) (tensor([0, 1, 2]), tensor([3, 4, 5]), tensor([6, 7, 8]), tensor([ 9, 10, 11]), tensor([12]))
Help improve this page
Found an error, an unclear step, or a missing example?

