conv1d
Builtin index · Statistics & ML
result = conv1d(x, kernel, [stride=], [padding=])
Input: x, kernel, stride, padding · Output: result
What it is
Slides a length-K learnable kernel vector over a length-N signal x, moving stride positions at a time (integer, default 1) with padding ("valid" — no padding, output shrinks — or "same" — zero-padded to keep the output length equal to N; default "valid").
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = conv1d(x, kernel, [stride=], [padding=]) | x vectornot documented yetkernel vectornot documented yetstride vector, optionalnot documented yetpadding vector, optionalnot documented yet | result vector | Returns the length-M convolved output vector, M depending on N, K, stride, and padding. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
x1d = [1.0, 2.0, 3.0, 4.0, 5.0]
edge_kernel = [1.0, 0.0, -1.0]
y1d = conv1d(x1d, edge_kernel)
print("conv1d edge response: {y1d}")
img = [1, 5, 2, 8; 4, 3, 9, 1; 7, 2, 6, 0; 1, 1, 1, 1]
k2d = [1, 0; 0, -1]
y2d = conv2d(img, k2d, 1, "valid")
print("conv2d output:\n{y2d}")
print("maxpool2d: {maxpool2d(img, 2)}")
print("avgpool2d: {avgpool2d(img, 2)}")
output
conv1d edge response: [-2, -2, -2] conv2d output: [-2, -4, 1; 2, -3, 9; 6, 1, 5] maxpool2d: [5, 9; 7, 6] avgpool2d: [3.25, 5; 2.75, 2]
from statistics-ml