FunctionRacerProblemsRace

Skip the Padding

HardPyTorchPython

Sequences of different lengths are stored as the rows of one table x, each padded at its end to the same width. lengths says how many leading elements of each row are real; the rest is padding and may hold anything. Return the mean of the real elements of each row.

Example 1

x [[1.0,2.0,9.0],[4.0,9.0,9.0]]
lengths [2,1]
returns [1.5,4.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