Slide a Kernel
Slide the 1-D tensor kernel along the 1-D tensor x, one step at a time, without going past either end. At each position, multiply the kernel with the elements under it and add up the products. Return those sums. Use F.conv1d.
Example 1
x [1.0,2.0,3.0,4.0]
kernel [1.0,2.0]
returns [5.0,8.0,11.0]
First 1·1 + 2·2 = 5, then 2·1 + 3·2 = 8, then 3·1 + 4·2 = 11.
Constraints
xhas 2 to 9 elementskernelhas 1 to 4, never more thanx
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More PyTorch problems
- The Second DerivativeHard
- Windows and TargetsHard
- A Table of ZerosBeginner
- Add Them UpBeginner
- Biggest and WhereBeginner
- Column AveragesBeginner
- Count UpBeginner
- Dot ProductBeginner