{"id":5690,"date":"2020-11-28T20:10:11","date_gmt":"2020-11-28T14:40:11","guid":{"rendered":"http:\/\/www.pythonpool.com\/?p=5690"},"modified":"2026-07-13T12:29:02","modified_gmt":"2026-07-13T06:59:02","slug":"numpy-convolve","status":"publish","type":"post","link":"https:\/\/www.pythonpool.com\/numpy-convolve\/","title":{"rendered":"NumPy convolve(): 1D Convolution Modes and Examples"},"content":{"rendered":"<p><strong>Quick answer:<\/strong> NumPy&#8217;s np.convolve computes the discrete one-dimensional convolution of two sequences. Use full when every overlap matters, same when the result should align with the first input length, and valid when only complete overlaps are meaningful. Remember that same mode uses the first argument&#8217;s length, so swapping operands can change the shape even though the mathematical convolution is commutative.<\/p>\n<figure class=\"pythonpool-article-visual\"><img src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/numpy-convolve.png\" alt=\"Python Pool infographic showing NumPy convolve sliding windows, full same valid modes, and output lengths\" width=\"1536\" height=\"1024\" loading=\"lazy\" decoding=\"async\"><figcaption>NumPy convolve slides one one-dimensional array across another; choose full, same, or valid mode from the signal and kernel lengths you need.<\/figcaption><\/figure>\n<p><code>numpy.convolve()<\/code> performs one-dimensional discrete convolution. It combines two sequences by sliding one sequence across the other and summing the overlapping products.<\/p>\n<p>The official NumPy documentation covers <a href=\"https:\/\/numpy.org\/doc\/stable\/reference\/generated\/numpy.convolve.html\">numpy.convolve()<\/a>, <a href=\"https:\/\/numpy.org\/doc\/stable\/reference\/generated\/numpy.polymul.html\">numpy.polymul()<\/a>, and SciPy&#8217;s <a href=\"https:\/\/docs.scipy.org\/doc\/scipy\/reference\/generated\/scipy.signal.fftconvolve.html\">fftconvolve()<\/a>.<\/p>\n<p><code>convolve()<\/code> is for one-dimensional inputs. If either input has more dimensions, flatten or choose a tool designed for multidimensional signal processing.<\/p>\n<p>The <code>mode<\/code> argument controls output length and boundary behavior. The default <code>full<\/code> mode returns every overlap, including partial overlaps at the edges. <code>same<\/code> returns an output with length equal to the longer input. <code>valid<\/code> returns only positions where the inputs fully overlap.<\/p>\n<p>Convolution is not the same as correlation. Convolution reverses one sequence before the sliding operation. That distinction matters for asymmetric kernels.<\/p>\n<p>For very large inputs, direct convolution can be slower than FFT-based methods. SciPy&#8217;s <code>fftconvolve()<\/code> is often a better choice when the arrays are large and the dependency is available.<\/p>\n<p>The order of the inputs usually does not change the full convolution result for numeric one-dimensional arrays, but it can change how you think about the operation. In signal examples, the longer array is often called the signal and the shorter array is often called the kernel or filter.<\/p>\n<p>Before using convolution in a data pipeline, decide how edge values should be handled. The mode controls how much edge overlap appears in the output, and explicit padding can make boundary assumptions easier to audit.<\/p>\n<p>Also keep dtype in mind. Integer inputs can produce integer outputs, while averaging kernels usually require floating-point values. If a kernel contains fractions, create it as a float array so the result reflects the intended math.<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-transparent ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #990303;color:#990303\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #990303;color:#990303\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.pythonpool.com\/numpy-convolve\/#Run_A_Basic_Convolution\" >Run A Basic Convolution<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.pythonpool.com\/numpy-convolve\/#Use_same_Mode\" >Use same Mode<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.pythonpool.com\/numpy-convolve\/#Use_valid_Mode\" >Use valid Mode<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.pythonpool.com\/numpy-convolve\/#Create_A_Moving_Average\" >Create A Moving Average<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.pythonpool.com\/numpy-convolve\/#Understand_Boundary_Padding\" >Understand Boundary Padding<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.pythonpool.com\/numpy-convolve\/#Multiply_Polynomial_Coefficients\" >Multiply Polynomial Coefficients<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.pythonpool.com\/numpy-convolve\/#Understand_The_Sliding_Window\" >Understand The Sliding Window<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.pythonpool.com\/numpy-convolve\/#Compare_full_same_And_valid\" >Compare full, same, And valid<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.pythonpool.com\/numpy-convolve\/#Normalize_A_Moving_Average\" >Normalize A Moving Average<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.pythonpool.com\/numpy-convolve\/#Validate_Inputs_And_Alignment\" >Validate Inputs And Alignment<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.pythonpool.com\/numpy-convolve\/#Frequently_Asked_Questions\" >Frequently Asked Questions<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.pythonpool.com\/numpy-convolve\/#What_does_NumPy_convolve_do\" >What does NumPy convolve do?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/www.pythonpool.com\/numpy-convolve\/#What_is_the_difference_between_full_same_and_valid\" >What is the difference between full same and valid?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/www.pythonpool.com\/numpy-convolve\/#Does_npconvolve_commute\" >Does np.convolve commute?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/www.pythonpool.com\/numpy-convolve\/#How_do_I_smooth_a_signal_with_convolve\" >How do I smooth a signal with convolve?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Run_A_Basic_Convolution\"><\/span>Run A Basic Convolution<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The default mode is <code>full<\/code>.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">import numpy as np\n\nsignal = np.array([1, 2, 3])\nkernel = np.array([1, 1])\n\nresult = np.convolve(signal, kernel)\n\nprint(result)\n<\/code><\/pre>\n<\/div>\n<p>This returns every overlap between the two one-dimensional arrays.<\/p>\n<p>The output is longer than the input signal because <code>full<\/code> mode includes edge overlaps.<\/p>\n<p>Use this mode when you need the complete convolution result.<\/p>\n<p>For input lengths <code>n<\/code> and <code>m<\/code>, full mode has length <code>n + m - 1<\/code>. That predictable length is useful when validating examples.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Use_same_Mode\"><\/span>Use same Mode<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><code>mode=\"same\"<\/code> returns an output with length equal to the longer input.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">import numpy as np\n\nsignal = np.array([1, 2, 3, 4])\nkernel = np.array([1, 0, -1])\n\nresult = np.convolve(signal, kernel, mode=\"same\")\n\nprint(result)\n<\/code><\/pre>\n<\/div>\n<p>This is convenient for filtering when you want the result length to match the signal length.<\/p>\n<p>Edge values still depend on partial overlap, so boundary interpretation matters.<\/p>\n<p>If edge behavior is important, inspect the first and last values carefully.<\/p>\n<p>Same mode is convenient, but it does not mean the edge values are calculated from full windows. It means the output is centered and trimmed to a familiar length.<\/p>\n<p><!-- Python Pool visual layout repair 2026-07-13 --><\/p>\n<figure class=\"pythonpool-article-visual pythonpool-supporting-visual\"><img src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/convolve-signal-b161.png\" alt=\"Python Pool infographic showing a one-dimensional signal, samples, kernel, and NumPy convolve\" width=\"1536\" height=\"1054\" loading=\"lazy\" decoding=\"async\"><figcaption>Input signal: A one-dimensional signal, samples, kernel, and NumPy convolve.<\/figcaption><\/figure>\n<h2><span class=\"ez-toc-section\" id=\"Use_valid_Mode\"><\/span>Use valid Mode<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><code>mode=\"valid\"<\/code> keeps only full-overlap positions.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">import numpy as np\n\nsignal = np.array([1, 2, 3, 4, 5])\nkernel = np.array([1, 1, 1])\n\nresult = np.convolve(signal, kernel, mode=\"valid\")\n\nprint(result)\n<\/code><\/pre>\n<\/div>\n<p>The output is shorter because partial edge overlaps are excluded.<\/p>\n<p>Use this mode when only complete windows should be included.<\/p>\n<p>This is common for sliding-window sums and simple finite impulse response filters.<\/p>\n<p>For input lengths <code>n<\/code> and <code>m<\/code>, valid mode has length <code>max(n, m) - min(n, m) + 1<\/code> when the longer input is at least as long as the shorter one.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Create_A_Moving_Average\"><\/span>Create A Moving Average<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>A normalized ones kernel creates a simple moving average.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">import numpy as np\n\nsignal = np.array([2, 4, 6, 8, 10], dtype=float)\nkernel = np.ones(3) \/ 3\n\naverage = np.convolve(signal, kernel, mode=\"valid\")\n\nprint(average)\n<\/code><\/pre>\n<\/div>\n<p>The kernel averages each group of three consecutive values.<\/p>\n<p><code>valid<\/code> mode avoids partial windows at the edges.<\/p>\n<p>Use <code>same<\/code> mode only if edge estimates are acceptable for your workflow.<\/p>\n<p>For a moving average, valid mode is often easier to explain because each output value uses the same number of input samples.<\/p>\n<figure class=\"pythonpool-article-visual pythonpool-supporting-visual\"><img src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/convolve-slide-b161.png\" alt=\"Python Pool infographic mapping a kernel across a signal through multiply, sum, and output samples\" width=\"1536\" height=\"1054\" loading=\"lazy\" decoding=\"async\"><figcaption>Slide kernel: A kernel across a signal through multiply, sum, and output samples.<\/figcaption><\/figure>\n<h2><span class=\"ez-toc-section\" id=\"Understand_Boundary_Padding\"><\/span>Understand Boundary Padding<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Padding can make boundary handling explicit before convolution.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">import numpy as np\n\nsignal = np.array([1, 2, 3, 4])\nkernel = np.array([1, 1, 1])\n\npadded = np.pad(signal, (1, 1), mode=\"edge\")\nresult = np.convolve(padded, kernel, mode=\"valid\")\n\nprint(result)\n<\/code><\/pre>\n<\/div>\n<p>Padding repeats the edge values before the convolution.<\/p>\n<p>This makes the boundary rule visible in the code.<\/p>\n<p>Different padding modes can produce different first and last values.<\/p>\n<p>Padding should be chosen for the domain, not just to make shapes line up. Repeating edges, adding zeros, and reflecting values all imply different assumptions about data outside the observed range.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Multiply_Polynomial_Coefficients\"><\/span>Multiply Polynomial Coefficients<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Convolution also appears when multiplying polynomial coefficient arrays.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">import numpy as np\n\nleft = np.array([1, 2])\nright = np.array([1, 3])\n\nproduct = np.convolve(left, right)\n\nprint(product)\n<\/code><\/pre>\n<\/div>\n<p>The output contains the coefficients of the product polynomial.<\/p>\n<p>For polynomial-specific code, <code>np.polymul()<\/code> can make the intent clearer.<\/p>\n<p>This connection is useful for understanding the operation, but signal-processing code should still name arrays according to their domain meaning.<\/p>\n<p>In short, use <code>np.convolve()<\/code> for one-dimensional convolution, choose <code>full<\/code>, <code>same<\/code>, or <code>valid<\/code> based on output length and boundary needs, and use explicit padding when the edge rule should be visible.<\/p>\n<figure class=\"pythonpool-article-visual pythonpool-supporting-visual\"><img src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/convolve-modes-b161.png\" alt=\"Python Pool infographic comparing full, same, and valid modes with output lengths and boundaries\" width=\"1536\" height=\"1054\" loading=\"lazy\" decoding=\"async\"><figcaption>Convolution modes: Full, same, and valid modes with output lengths and boundaries.<\/figcaption><\/figure>\n<h2><span class=\"ez-toc-section\" id=\"Understand_The_Sliding_Window\"><\/span>Understand The Sliding Window<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>A convolution combines one sequence with a reversed sliding copy of the other. In signal work, the second sequence is often a short kernel such as a moving average. Keep the kernel&#8217;s meaning and normalization explicit.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">import numpy as np\n\nsignal = np.array([2, 4, 6, 8])\nkernel = np.array([0.25, 0.5, 0.25])\nfiltered = np.convolve(signal, kernel, mode=\"full\")\nprint(filtered)\n<\/code><\/pre>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Compare_full_same_And_valid\"><\/span>Compare full, same, And valid<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The three modes describe which overlap positions are returned. full is longest, same has the first input length, and valid excludes positions where the shorter array only partially overlaps the longer one. Check lengths when downstream code expects alignment.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">import numpy as np\n\nleft = np.array([1, 2, 3, 4])\nright = np.array([1, 1])\nfor mode in (\"full\", \"same\", \"valid\"):\n    result = np.convolve(left, right, mode=mode)\n    print(mode, len(result), result)\n<\/code><\/pre>\n<\/div>\n<figure class=\"pythonpool-article-visual pythonpool-supporting-visual\"><img src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/convolve-check-b161.png\" alt=\"Python Pool infographic testing empty input, reversal, dtype, boundaries, and correlation confusion\" width=\"1536\" height=\"1054\" loading=\"lazy\" decoding=\"async\"><figcaption>Signal checks: Empty input, reversal, dtype, boundaries, and correlation confusion.<\/figcaption><\/figure>\n<h2><span class=\"ez-toc-section\" id=\"Normalize_A_Moving_Average\"><\/span>Normalize A Moving Average<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>A kernel of ones adds a window; dividing by the window length turns it into an average. Edge values still depend on the chosen mode, so document whether the result is padded, centered, or shorter than the original signal.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">import numpy as np\n\nwindow = 3\nsignal = np.array([3, 6, 9, 12, 15])\nkernel = np.ones(window) \/ window\nsmoothed = np.convolve(signal, kernel, mode=\"same\")\nprint(smoothed)\n<\/code><\/pre>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Validate_Inputs_And_Alignment\"><\/span>Validate Inputs And Alignment<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>np.convolve expects one-dimensional array-like inputs. Flattening a matrix may hide a data-shape bug, so reject unexpected dimensions near the boundary and test a short known example before processing a large signal.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">import numpy as np\n\n\ndef convolve_1d(signal, kernel, mode=\"same\"):\n    signal = np.asarray(signal)\n    kernel = np.asarray(kernel)\n    if signal.ndim != 1 or kernel.ndim != 1:\n        raise ValueError(\"signal and kernel must be one-dimensional\")\n    return np.convolve(signal, kernel, mode=mode)\n\nprint(convolve_1d([1, 2, 3], [1, 0]))\n<\/code><\/pre>\n<\/div>\n<p>NumPy documents <a href=\"https:\/\/numpy.org\/doc\/stable\/reference\/generated\/numpy.convolve.html\">np.convolve()<\/a>, including its one-dimensional inputs, output modes, and commutative behavior. Related references include <a href=\"https:\/\/www.pythonpool.com\/moving-average-python\/\">moving averages<\/a>, <a href=\"https:\/\/www.pythonpool.com\/numpy-diff\/\">NumPy differences<\/a>, and <a href=\"https:\/\/www.pythonpool.com\/numpy-reshape-3d-to-2d\/\">array shape conversion<\/a>.<\/p>\n<p>For related signal-processing tasks, compare <a href=\"https:\/\/www.pythonpool.com\/moving-average-python\/\">moving averages<\/a>, <a href=\"https:\/\/www.pythonpool.com\/numpy-diff\/\">NumPy differences<\/a>, and <a href=\"https:\/\/www.pythonpool.com\/numpy-reshape-3d-to-2d\/\">array reshaping<\/a> when preparing inputs and interpreting output length.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Frequently_Asked_Questions\"><\/span>Frequently Asked Questions<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"What_does_NumPy_convolve_do\"><\/span>What does NumPy convolve do?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>It computes the discrete one-dimensional convolution of two sequences, often used for smoothing and filtering.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"What_is_the_difference_between_full_same_and_valid\"><\/span>What is the difference between full same and valid?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>full returns every overlap, same matches the first input length, and valid keeps only complete overlaps.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Does_npconvolve_commute\"><\/span>Does np.convolve commute?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>For the mathematical convolution, swapping the inputs gives the same values, but same mode uses the first input to choose the output length.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"How_do_I_smooth_a_signal_with_convolve\"><\/span>How do I smooth a signal with convolve?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Normalize a moving-average kernel such as np.ones(window)\/window and apply it with the mode that matches your edge policy.<\/p>\n<p><script type=\"application\/ld+json\">{\"@context\":\"https:\/\/schema.org\",\"@type\":\"FAQPage\",\"mainEntity\":[{\"@type\":\"Question\",\"name\":\"What does NumPy convolve do?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"It computes the discrete one-dimensional convolution of two sequences, often used for smoothing and filtering.\"}},{\"@type\":\"Question\",\"name\":\"What is the difference between full same and valid?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"full returns every overlap, same matches the first input length, and valid keeps only complete overlaps.\"}},{\"@type\":\"Question\",\"name\":\"Does np.convolve commute?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"For the mathematical convolution, swapping the inputs gives the same values, but same mode uses the first input to choose the output length.\"}},{\"@type\":\"Question\",\"name\":\"How do I smooth a signal with convolve?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Normalize a moving-average kernel such as np.ones(window)\/window and apply it with the mode that matches your edge policy.\"}}]}<\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Use NumPy convolve for one-dimensional signals, understand full same and valid modes, choose operand order, and avoid unexpected output lengths.<\/p>\n","protected":false},"author":1,"featured_media":33994,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[1495],"tags":[2570,2571,2569],"class_list":["post-5690","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-numpy","tag-convolve-numpy","tag-numpy-convolve","tag-numpy-convolve-2d","infinite-scroll-item"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v20.1 (Yoast SEO v28.0) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>NumPy convolve(): 1D Convolution Modes and Examples<\/title>\n<meta name=\"description\" content=\"Use NumPy convolve for one-dimensional signals, understand full same and valid modes, choose operand order, and avoid unexpected output lengths.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pythonpool.com\/numpy-convolve\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"NumPy convolve(): 1D Convolution Modes and Examples\" \/>\n<meta property=\"og:description\" content=\"Use NumPy convolve for one-dimensional signals, understand full same and valid modes, choose operand order, and avoid unexpected output lengths.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pythonpool.com\/numpy-convolve\/\" \/>\n<meta property=\"og:site_name\" content=\"Python Pool\" \/>\n<meta property=\"article:published_time\" content=\"2020-11-28T14:40:11+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-07-13T06:59:02+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/numpy-convolve.png\" \/>\n<meta name=\"author\" content=\"Python Pool\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:title\" content=\"Python Pool\" \/>\n<meta name=\"twitter:description\" content=\"Practical Python tutorials, error fixes, code examples, and project guides.\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/numpy-convolve.png\" \/>\n<meta name=\"twitter:creator\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:site\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Python Pool\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/numpy-convolve\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/numpy-convolve\\\/\"},\"author\":{\"name\":\"Python Pool\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#\\\/schema\\\/person\\\/f87448ee54c0ffd2889fbf2408c18998\"},\"headline\":\"NumPy convolve(): 1D Convolution Modes and Examples\",\"datePublished\":\"2020-11-28T14:40:11+00:00\",\"dateModified\":\"2026-07-13T06:59:02+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/numpy-convolve\\\/\"},\"wordCount\":1111,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/numpy-convolve\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/numpy-convolve-1d-convolution-modes-guide-pythonpool.png\",\"keywords\":[\"convolve numpy\",\"numpy convolve\",\"numpy convolve 2d\"],\"articleSection\":[\"Numpy\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.pythonpool.com\\\/numpy-convolve\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/numpy-convolve\\\/\",\"url\":\"https:\\\/\\\/www.pythonpool.com\\\/numpy-convolve\\\/\",\"name\":\"NumPy convolve(): 1D Convolution Modes and Examples\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/numpy-convolve\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/numpy-convolve\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/numpy-convolve-1d-convolution-modes-guide-pythonpool.png\",\"datePublished\":\"2020-11-28T14:40:11+00:00\",\"dateModified\":\"2026-07-13T06:59:02+00:00\",\"description\":\"Use NumPy convolve for one-dimensional signals, understand full same and valid modes, choose operand order, and avoid unexpected output lengths.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/numpy-convolve\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pythonpool.com\\\/numpy-convolve\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/numpy-convolve\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/numpy-convolve-1d-convolution-modes-guide-pythonpool.png\",\"contentUrl\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/numpy-convolve-1d-convolution-modes-guide-pythonpool.png\",\"width\":1350,\"height\":650,\"caption\":\"NumPy convolve 1D convolution modes guide\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/numpy-convolve\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.pythonpool.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"NumPy convolve(): 1D Convolution Modes and Examples\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#website\",\"url\":\"https:\\\/\\\/www.pythonpool.com\\\/\",\"name\":\"Python Pool\",\"description\":\"Practical Python tutorials, error fixes, code examples, and project guides.\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.pythonpool.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#organization\",\"name\":\"Python Pool\",\"url\":\"https:\\\/\\\/www.pythonpool.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/aa.png\",\"contentUrl\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/aa.png\",\"width\":452,\"height\":185,\"caption\":\"Python Pool\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/x.com\\\/pythonpool\",\"https:\\\/\\\/www.youtube.com\\\/c\\\/pythonpool\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#\\\/schema\\\/person\\\/f87448ee54c0ffd2889fbf2408c18998\",\"name\":\"Python Pool\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/fdd3cb9ad7f560324dfd481989550aa8ffce84388fd253c42beca35c999d3108?s=96&d=wavatar&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/fdd3cb9ad7f560324dfd481989550aa8ffce84388fd253c42beca35c999d3108?s=96&d=wavatar&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/fdd3cb9ad7f560324dfd481989550aa8ffce84388fd253c42beca35c999d3108?s=96&d=wavatar&r=g\",\"caption\":\"Python Pool\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"NumPy convolve(): 1D Convolution Modes and Examples","description":"Use NumPy convolve for one-dimensional signals, understand full same and valid modes, choose operand order, and avoid unexpected output lengths.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.pythonpool.com\/numpy-convolve\/","og_locale":"en_US","og_type":"article","og_title":"NumPy convolve(): 1D Convolution Modes and Examples","og_description":"Use NumPy convolve for one-dimensional signals, understand full same and valid modes, choose operand order, and avoid unexpected output lengths.","og_url":"https:\/\/www.pythonpool.com\/numpy-convolve\/","og_site_name":"Python Pool","article_published_time":"2020-11-28T14:40:11+00:00","article_modified_time":"2026-07-13T06:59:02+00:00","og_image":[{"url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/numpy-convolve.png","type":"","width":"","height":""}],"author":"Python Pool","twitter_card":"summary_large_image","twitter_title":"Python Pool","twitter_description":"Practical Python tutorials, error fixes, code examples, and project guides.","twitter_image":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/numpy-convolve.png","twitter_creator":"@pythonpool","twitter_site":"@pythonpool","twitter_misc":{"Written by":"Python Pool","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.pythonpool.com\/numpy-convolve\/#article","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/numpy-convolve\/"},"author":{"name":"Python Pool","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/f87448ee54c0ffd2889fbf2408c18998"},"headline":"NumPy convolve(): 1D Convolution Modes and Examples","datePublished":"2020-11-28T14:40:11+00:00","dateModified":"2026-07-13T06:59:02+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pythonpool.com\/numpy-convolve\/"},"wordCount":1111,"commentCount":0,"publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"image":{"@id":"https:\/\/www.pythonpool.com\/numpy-convolve\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/numpy-convolve-1d-convolution-modes-guide-pythonpool.png","keywords":["convolve numpy","numpy convolve","numpy convolve 2d"],"articleSection":["Numpy"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pythonpool.com\/numpy-convolve\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.pythonpool.com\/numpy-convolve\/","url":"https:\/\/www.pythonpool.com\/numpy-convolve\/","name":"NumPy convolve(): 1D Convolution Modes and Examples","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pythonpool.com\/numpy-convolve\/#primaryimage"},"image":{"@id":"https:\/\/www.pythonpool.com\/numpy-convolve\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/numpy-convolve-1d-convolution-modes-guide-pythonpool.png","datePublished":"2020-11-28T14:40:11+00:00","dateModified":"2026-07-13T06:59:02+00:00","description":"Use NumPy convolve for one-dimensional signals, understand full same and valid modes, choose operand order, and avoid unexpected output lengths.","breadcrumb":{"@id":"https:\/\/www.pythonpool.com\/numpy-convolve\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pythonpool.com\/numpy-convolve\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/numpy-convolve\/#primaryimage","url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/numpy-convolve-1d-convolution-modes-guide-pythonpool.png","contentUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/numpy-convolve-1d-convolution-modes-guide-pythonpool.png","width":1350,"height":650,"caption":"NumPy convolve 1D convolution modes guide"},{"@type":"BreadcrumbList","@id":"https:\/\/www.pythonpool.com\/numpy-convolve\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pythonpool.com\/"},{"@type":"ListItem","position":2,"name":"NumPy convolve(): 1D Convolution Modes and Examples"}]},{"@type":"WebSite","@id":"https:\/\/www.pythonpool.com\/#website","url":"https:\/\/www.pythonpool.com\/","name":"Python Pool","description":"Practical Python tutorials, error fixes, code examples, and project guides.","publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pythonpool.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.pythonpool.com\/#organization","name":"Python Pool","url":"https:\/\/www.pythonpool.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","contentUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","width":452,"height":185,"caption":"Python Pool"},"image":{"@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/pythonpool","https:\/\/www.youtube.com\/c\/pythonpool"]},{"@type":"Person","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/f87448ee54c0ffd2889fbf2408c18998","name":"Python Pool","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/fdd3cb9ad7f560324dfd481989550aa8ffce84388fd253c42beca35c999d3108?s=96&d=wavatar&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/fdd3cb9ad7f560324dfd481989550aa8ffce84388fd253c42beca35c999d3108?s=96&d=wavatar&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/fdd3cb9ad7f560324dfd481989550aa8ffce84388fd253c42beca35c999d3108?s=96&d=wavatar&r=g","caption":"Python Pool"}}]}},"_links":{"self":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/5690","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/comments?post=5690"}],"version-history":[{"count":21,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/5690\/revisions"}],"predecessor-version":[{"id":41461,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/5690\/revisions\/41461"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media\/33994"}],"wp:attachment":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media?parent=5690"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/categories?post=5690"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/tags?post=5690"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}