Skip the Padding
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
- 1 to 4 rows, 1 to 6 columns
- Every length is at least 1
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More PyTorch problems
- Slide a KernelHard
- The Second DerivativeHard
- Windows and TargetsHard
- A Table of ZerosBeginner
- Add Them UpBeginner
- Biggest and WhereBeginner
- Column AveragesBeginner
- Count UpBeginner