FunctionRacerProblemsRace

Slide a Kernel

HardPyTorchPython

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

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