{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {
    "Notes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Admonition",
          "__tag": 4056,
          "kind": "warning",
          "base_type": "warning",
          "children": [
            {
              "__type": "AdmonitionTitle",
              "__tag": 4055,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "warning "
                }
              ]
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "This function creates views with overlapping memory. When "
                },
                {
                  "__type": "InlineCode",
                  "__tag": 4051,
                  "value": "writeable=True"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": ", writing to the view will modify the original array and may affect multiple view positions. See the examples below and "
                },
                {
                  "__type": "CrossRef",
                  "__tag": 4002,
                  "value": "this guide",
                  "reference": {
                    "__type": "LocalRef",
                    "__tag": 4022,
                    "kind": "docs",
                    "path": "/user/basics.copies"
                  },
                  "kind": "docs"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " about the difference between copies and views."
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "For many applications using a sliding window view can be convenient, but potentially very slow. Often specialized solutions exist, for example:"
            }
          ]
        },
        {
          "__type": "BulletList",
          "__tag": 4053,
          "ordered": false,
          "start": 1,
          "children": [
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "scipy.signal.fftconvolve",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "scipy",
                        "version": "*",
                        "kind": "api",
                        "path": "scipy.signal._signaltools:fftconvolve"
                      },
                      "kind": "module"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "filtering functions in "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "scipy.ndimage",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "scipy",
                        "version": "*",
                        "kind": "api",
                        "path": "scipy.ndimage"
                      },
                      "kind": "module"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "moving window functions provided by   "
                    },
                    {
                      "__type": "Link",
                      "__tag": 4049,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "bottleneck"
                        }
                      ],
                      "url": "https://github.com/pydata/bottleneck",
                      "title": ""
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "As a rough estimate, a sliding window approach with an input size of "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "N",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and a window size of "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "W",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " will scale as "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "O(N*W)",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " where frequently a special algorithm can achieve "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "O(N)",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". That means that the sliding window variant for a window size of 100 can be a 100 times slower than a more specialized version."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Nevertheless, for small window sizes, when no custom algorithm exists, or as a prototyping and developing tool, this function can be a good solution."
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Warns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Raises": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Yields": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Methods": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Returns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Parameters",
          "__tag": 4026,
          "children": [
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "view",
              "annotation": "ndarray",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Sliding window view of the array. The sliding window dimensions are inserted at the end, and the original dimensions are trimmed as required by the size of the sliding window. That is, "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "view.shape = x_shape_trimmed + window_shape"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", where "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "x_shape_trimmed"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "x.shape"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " with every entry reduced by one less than the corresponding window size."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Create a sliding window view into the array with the given window shape."
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Receives": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Warnings": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Attributes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Parameters",
          "__tag": 4026,
          "children": [
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "x",
              "annotation": "array_like",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Array to create the sliding window view from."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "window_shape",
              "annotation": "int or tuple of int",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Size of window over each axis that takes part in the sliding window. If "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "axis"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is not present, must have same length as the number of input array dimensions. Single integers "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "i",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " are treated as if they were the tuple "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "(i,)",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "axis",
              "annotation": "int or tuple of int, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Axis or axes along which the sliding window is applied. By default, the sliding window is applied to all axes and "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "window_shape[i]",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " will refer to axis "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "i",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " of "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "x"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". If "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "axis"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is given as a "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "tuple of int",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "window_shape[i]",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " will refer to the axis "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "axis[i]",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " of "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "x"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". Single integers "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "i",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " are treated as if they were the tuple "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "(i,)",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "subok",
              "annotation": "bool, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "If True, sub-classes will be passed-through, otherwise the returned array will be forced to be a base-class array (default)."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "writeable",
              "annotation": "bool, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "When true, allow writing to the returned view. The default is false, as this should be used with caution: the returned view contains the same memory location multiple times, so writing to one location will cause others to change."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Extended Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Also known as rolling or moving window, the window slides across all dimensions of the array and extracts subsets of the array at all window positions."
            }
          ]
        },
        {
          "__type": "Admonition",
          "__tag": 4056,
          "kind": "versionadded",
          "base_type": "neutral",
          "children": [
            {
              "__type": "AdmonitionTitle",
              "__tag": 4055,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "versionadded 1.20.0"
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Other Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    }
  },
  "_ordered_sections": [
    "Summary",
    "Extended Summary",
    "Parameters",
    "Attributes",
    "Methods",
    "Returns",
    "Yields",
    "Receives",
    "Other Parameters",
    "Raises",
    "Warns",
    "Warnings",
    "Notes"
  ],
  "item_file": "build-install/usr/lib/python3.14/site-packages/numpy/lib/_stride_tricks_impl.py",
  "item_line": 119,
  "item_type": "_ArrayFunctionDispatcher",
  "aliases": [
    "numpy.lib._stride_tricks_impl.sliding_window_view"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "import numpy as np\nfrom numpy.lib.stride_tricks import sliding_window_view\nx = np.arange(6)\nx.shape\nv = sliding_window_view(x, 3)\nv.shape\nv\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nThis also works in more dimensions, e.g.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "i, j = np.ogrid[:3, :4]\nx = 10*i + j\nx.shape\nx\nshape = (2,2)\nv = sliding_window_view(x, shape)\nv.shape\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "v\n",
        "execution_status": "failure"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nThe axis can be specified explicitly:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "v = sliding_window_view(x, 3, 0)\nv.shape\nv\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nThe same axis can be used several times. In that case, every use reduces\nthe corresponding original dimension:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "v = sliding_window_view(x, (2, 3), (1, 1))\nv.shape\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "v\n",
        "execution_status": "failure"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nCombining with stepped slicing (`::step`), this can be used to take sliding\nviews which skip elements:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "x = np.arange(7)\nsliding_window_view(x, 5)[:, ::2]\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nor views which move by multiple elements\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "x = np.arange(7)\nsliding_window_view(x, 3)[::2, :]\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nA common application of `sliding_window_view` is the calculation of running\nstatistics. The simplest example is the\n`moving average <https://en.wikipedia.org/wiki/Moving_average>`_:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "x = np.arange(6)\nx.shape\nv = sliding_window_view(x, 3)\nv.shape\nv\nmoving_average = v.mean(axis=-1)\nmoving_average\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nThe two examples below demonstrate the effect of ``writeable=True``.\n\nCreating a view with the default ``writeable=False`` and then writing to\nit raises an error.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "v = sliding_window_view(x, 3)\nv[0,1] = 10\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nCreating a view with ``writeable=True`` and then writing to it changes\nthe original array and multiple view positions.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "x = np.arange(6)  # reset x for the second example\nv = sliding_window_view(x, 3, writeable=True)\nv[0,1] = 10\nx\nv\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nNote that a sliding window approach is often **not** optimal (see Notes)."
      }
    ],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "broadcast_to",
        "reference": {
          "__type": "LocalRef",
          "__tag": 4022,
          "kind": "module",
          "path": "numpy:broadcast_to"
        },
        "kind": "module"
      },
      "descriptions": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "broadcast an array to a given shape."
            }
          ]
        }
      ],
      "type": null
    },
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "lib.stride_tricks.as_strided",
        "reference": {
          "__type": "LocalRef",
          "__tag": 4022,
          "kind": "module",
          "path": "numpy.lib.stride_tricks:as_strided"
        },
        "kind": "module"
      },
      "descriptions": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "A lower-level and less safe routine for creating arbitrary views from custom shape and strides."
            }
          ]
        }
      ],
      "type": null
    }
  ],
  "signature": {
    "__type": "SignatureNode",
    "__tag": 4029,
    "kind": "function",
    "parameters": [
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "x",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "window_shape",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "axis",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "subok",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "KEYWORD_ONLY",
        "default": "False"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "writeable",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "KEYWORD_ONLY",
        "default": "False"
      }
    ],
    "return_annotation": {
      "__type": "Empty",
      "__tag": 4031
    },
    "target_name": "sliding_window_view"
  },
  "references": null,
  "qa": "numpy.lib.stride_tricks:sliding_window_view",
  "arbitrary": [],
  "local_refs": [
    "axis",
    "subok",
    "view",
    "window_shape",
    "writeable",
    "x"
  ]
}