{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {
    "Notes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "For a single dimension array "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "x"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "dct(x, norm='ortho')"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is equal to MATLAB "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "dct(x)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "There are, theoretically, 8 types of the DCT, only the first 4 types are implemented in scipy. 'The' DCT generally refers to DCT type 2, and 'the' Inverse DCT generally refers to DCT type 3."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Strong",
              "__tag": 4048,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Type I"
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "There are several definitions of the DCT-I; we use the following (for "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "norm=None"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ")"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "y_k = x_0 + (-1)^k x_{N-1} + 2 \\sum_{n=1}^{N-2} x_n \\cos\\left(\n\\frac{\\pi k n}{N-1} \\right)"
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "If "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "norm='ortho'"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "x[0]"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "x[N-1]"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " are multiplied by a scaling factor of "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\sqrt{2}"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", and "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "y[k]"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is multiplied by a scaling factor "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "f"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "f = \\begin{cases}\n \\frac{1}{2}\\sqrt{\\frac{1}{N-1}} & \\text{if }k=0\\text{ or }N-1, \\\\\n \\frac{1}{2}\\sqrt{\\frac{2}{N-1}} & \\text{otherwise} \\end{cases}"
        },
        {
          "__type": "Admonition",
          "__tag": 4056,
          "kind": "versionadded",
          "base_type": "neutral",
          "children": [
            {
              "__type": "AdmonitionTitle",
              "__tag": 4055,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "versionadded 1.2.0"
                }
              ]
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Orthonormalization in DCT-I."
                }
              ]
            }
          ]
        },
        {
          "__type": "Admonition",
          "__tag": 4056,
          "kind": "note",
          "base_type": "note",
          "children": [
            {
              "__type": "AdmonitionTitle",
              "__tag": 4055,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "note "
                }
              ]
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "The DCT-I is only supported for input size > 1."
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Strong",
              "__tag": 4048,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Type II"
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "There are several definitions of the DCT-II; we use the following (for "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "norm=None"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ")"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "y_k = 2 \\sum_{n=0}^{N-1} x_n \\cos\\left(\\frac{\\pi k(2n+1)}{2N} \\right)"
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "If "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "norm='ortho'"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "y[k]"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is multiplied by a scaling factor "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "f"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "f = \\begin{cases}\n\\sqrt{\\frac{1}{4N}} & \\text{if }k=0, \\\\\n\\sqrt{\\frac{1}{2N}} & \\text{otherwise} \\end{cases}"
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "which makes the corresponding matrix of coefficients orthonormal ("
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "O @ O.T = np.eye(N)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ")."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Strong",
              "__tag": 4048,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Type III"
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "There are several definitions, we use the following (for "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "norm=None"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ")"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "y_k = x_0 + 2 \\sum_{n=1}^{N-1} x_n \\cos\\left(\\frac{\\pi(2k+1)n}{2N}\\right)"
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "or, for "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "norm='ortho'"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "y_k = \\frac{x_0}{\\sqrt{N}} + \\sqrt{\\frac{2}{N}} \\sum_{n=1}^{N-1} x_n\n\\cos\\left(\\frac{\\pi(2k+1)n}{2N}\\right)"
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The (unnormalized) DCT-III is the inverse of the (unnormalized) DCT-II, up to a factor "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "2N"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". The orthonormalized DCT-III is exactly the inverse of the orthonormalized DCT-II."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Strong",
              "__tag": 4048,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Type IV"
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "There are several definitions of the DCT-IV; we use the following (for "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "norm=None"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ")"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "y_k = 2 \\sum_{n=0}^{N-1} x_n \\cos\\left(\\frac{\\pi(2k+1)(2n+1)}{4N} \\right)"
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "If "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "norm='ortho'"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "y[k]"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is multiplied by a scaling factor "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "f"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "f = \\frac{1}{\\sqrt{2N}}"
        },
        {
          "__type": "Admonition",
          "__tag": 4056,
          "kind": "versionadded",
          "base_type": "neutral",
          "children": [
            {
              "__type": "AdmonitionTitle",
              "__tag": 4055,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "versionadded 1.2.0"
                }
              ]
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Support for DCT-IV."
                }
              ]
            }
          ]
        }
      ],
      "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": "y",
              "annotation": "ndarray of real",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The transformed input array."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Return the Discrete Cosine Transform of arbitrary type sequence x."
            }
          ]
        }
      ],
      "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": "The input array."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "type",
              "annotation": "{1, 2, 3, 4}, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Type of the DCT (see Notes). Default type is 2."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "n",
              "annotation": "int, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Length of the transform.  If "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "n < x.shape[axis]"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "x"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is truncated.  If "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "n > x.shape[axis]"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "x"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is zero-padded. The default results in "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "n = x.shape[axis]"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "axis",
              "annotation": "int, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Axis along which the dct is computed; the default is over the last axis (i.e., "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "axis=-1"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ")."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "norm",
              "annotation": "{None, 'ortho'}, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Normalization mode (see Notes). Default is None."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "overwrite_x",
              "annotation": "bool, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "If True, the contents of "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "x"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " can be destroyed; the default is False."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Extended Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "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": "/scipy/fftpack/_realtransforms.py",
  "item_line": 235,
  "item_type": "function",
  "aliases": [
    "scipy.fftpack.dct"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "The Type 1 DCT is equivalent to the FFT (though faster) for real,\neven-symmetrical inputs. The output is also real and even-symmetrical.\nHalf of the FFT input is used to generate half of the FFT output:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "from scipy.fftpack import fft, dct\nimport numpy as np\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "fft(np.array([4., 3., 5., 10., 5., 3.])).real\ndct(np.array([4., 3., 5., 10.]), 1)\n",
        "execution_status": "failure"
      }
    ],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "idct",
        "reference": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "current-module",
          "version": "current-version",
          "kind": "to-resolve",
          "path": "idct"
        },
        "kind": "module"
      },
      "descriptions": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Inverse DCT"
            }
          ]
        }
      ],
      "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": "type",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "2"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "n",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "axis",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "-1"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "norm",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "overwrite_x",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "False"
      }
    ],
    "return_annotation": {
      "__type": "Empty",
      "__tag": 4031
    },
    "target_name": "dct"
  },
  "references": [
    ".. [1] 'A Fast Cosine Transform in One and Two Dimensions', by J.",
    "       Makhoul, `IEEE Transactions on acoustics, speech and signal",
    "       processing` vol. 28(1), pp. 27-34,",
    "       :doi:`10.1109/TASSP.1980.1163351` (1980).",
    ".. [2] Wikipedia, \"Discrete cosine transform\",",
    "       https://en.wikipedia.org/wiki/Discrete_cosine_transform"
  ],
  "qa": "scipy.fftpack._realtransforms:dct",
  "arbitrary": [],
  "local_refs": [
    "axis",
    "n",
    "norm",
    "overwrite_x",
    "type",
    "x",
    "y"
  ]
}