{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {},
  "_ordered_sections": [],
  "item_file": null,
  "item_line": null,
  "item_type": null,
  "aliases": [],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [],
  "signature": null,
  "references": null,
  "qa": "user:how-to-print",
  "arbitrary": [
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "This page explains how to control the formatting of printed NumPy arrays. Note that these printing options apply only to arrays, not to scalars."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Printing NumPy Arrays"
        }
      ],
      "level": 0,
      "target": "how-to-print"
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Defining printing options"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Use "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.set_printoptions",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy:set_printoptions"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " to change printing options for the entire runtime session. To inspect current print settings, use "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.get_printoptions",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy:get_printoptions"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ":"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> np.set_printoptions(precision=2)\n>>> np.get_printoptions()\n{'edgeitems': 3, 'threshold': 1000, 'floatmode': 'maxprec', 'precision': 2, 'suppress': False, 'linewidth': 75, 'nanstr': 'nan', 'infstr': 'inf', 'sign': '-', 'formatter': None, 'legacy': False, 'override_repr': None}",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "To restore the default settings, use:"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> np.set_printoptions(edgeitems=3, infstr='inf',\n... linewidth=75, nanstr='nan', precision=8,\n... suppress=False, threshold=1000, formatter=None)",
              "execution_status": null
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Applying settings globally"
        }
      ],
      "level": 2,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Use "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.printoptions",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy:printoptions"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " as a context manager to temporarily override print settings within a specific scope:"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> arr = np.array([0.155, 0.184, 0.173])\n>>> with np.printoptions(precision=2):\n...     print(arr)\n[0.15 0.18 0.17]",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "All keywords that apply to "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.set_printoptions",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy:set_printoptions"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " also apply to "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.printoptions",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy:printoptions"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Applying settings temporarily"
        }
      ],
      "level": 2,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The default number of fractional digits displayed is 8. You can change this number using "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "precision"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " keyword."
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> arr = np.array([0.1, 0.184, 0.17322])\n>>> with np.printoptions(precision=2):\n...     print(arr)\n[0.1 0.18 0.17]",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "floatmode"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " option determines how the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "precision"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " setting is interpreted.  By default, "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "floatmode=maxprec_equal"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " displays values with the minimal number of digits needed to uniquely represent them,  using the same number of digits across all elements. If you want to show exactly the same number of digits specified by "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "precision"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", use "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "floatmode=fixed"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ":"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> arr = np.array([0.1, 0.184, 0.173], dtype=np.float32)\n>>> with np.printoptions(precision=2, floatmode=\"fixed\"):\n...     print(arr)\n[0.10 0.18 0.17]",
              "execution_status": null
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Changing the number of digits of precision"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "By default, "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "numpy.nan",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is displayed as "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "nan",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "numpy.inf",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is displayed as "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "inf",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". You can override these representations using the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "nanstr"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "infstr"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " options:"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> arr = np.array([np.inf, np.nan, 0])\n>>> with np.printoptions(nanstr=\"NAN\", infstr=\"INF\"):\n...     print(arr)\n[INF NAN  0.]",
              "execution_status": null
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Changing how "
        },
        {
          "__type": "InlineRole",
          "__tag": 4003,
          "value": "nan",
          "domain": null,
          "role": null,
          "inventory": null
        },
        {
          "__type": "Text",
          "__tag": 4046,
          "value": " and "
        },
        {
          "__type": "InlineRole",
          "__tag": 4003,
          "value": "inf",
          "domain": null,
          "role": null,
          "inventory": null
        },
        {
          "__type": "Text",
          "__tag": 4046,
          "value": " are displayed"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "By default, NumPy uses scientific notation when:"
            }
          ]
        },
        {
          "__type": "BulletList",
          "__tag": 4053,
          "ordered": false,
          "start": 1,
          "children": [
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The absolute value of the smallest number is less than "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "1e-4"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", or"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The ratio of the largest to the smallest absolute value is greater than "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "1e3"
                    }
                  ]
                },
                {
                  "__type": "Blockquote",
                  "__tag": 4059,
                  "children": [
                    {
                      "__type": "Code",
                      "__tag": 4050,
                      "value": ">>> arr = np.array([0.00002, 210000.0, 3.14])\n>>> print(arr)\n[2.00e-05 2.10e+05 3.14e+00]",
                      "execution_status": null
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "To suppress scientific notation and always use fixed-point notation, set "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "suppress=True"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ":"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> arr = np.array([0.00002, 210000.0, 3.14])\n>>> with np.printoptions(suppress=True):\n...     print(arr)\n[     0.00002 210000.           3.14   ]",
              "execution_status": null
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Controlling scientific notations"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "You can apply custom formatting functions to specific or all data types using "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "formatter"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " keyword. See "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.set_printoptions",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy:set_printoptions"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " for more details on supported format keys."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "For example, to format "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "datetime64",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " values with a custom function:"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> arr = np.array([np.datetime64(\"2025-01-01\"), np.datetime64(\"2024-01-01\")])\n>>> with np.printoptions(formatter={\"datetime\":lambda x: f\"(Year: {x.item().year}, Month: {x.item().month})\"}):\n...     print(arr)\n[(Year: 2025, Month: 1) (Year: 2024, Month: 1)]",
              "execution_status": null
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Applying custom formatting functions"
        }
      ],
      "level": 1,
      "target": null
    }
  ],
  "local_refs": []
}