FunctionRacerProblemsRace

In Batches

MediumPyTorchPython

Cut the 1-D tensor x into batches of size elements, in order. The last batch holds what is left and may be shorter. Return the sum of each batch, as a 1-D tensor.

Example 1

x [1.0,2.0,3.0,4.0,5.0]
size 2
returns [3.0,7.0,5.0]

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More PyTorch problems