{
  "__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-io",
  "arbitrary": [
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "how-to-io"
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "This page tackles common applications; for the full collection of I/O routines, see "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "routines.io",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "docs",
                "path": "reference:routines.io"
              },
              "kind": "exists"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Reading and writing files"
        }
      ],
      "level": 0,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Reading text and "
        },
        {
          "__type": "InlineRole",
          "__tag": 4003,
          "value": "CSV_",
          "domain": null,
          "role": null,
          "inventory": null
        },
        {
          "__type": "Text",
          "__tag": 4046,
          "value": " files"
        }
      ],
      "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.loadtxt",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy:loadtxt"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "With no missing values"
        }
      ],
      "level": 2,
      "target": "CSV"
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Use "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.genfromtxt",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy:genfromtxt"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.genfromtxt",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy:genfromtxt"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " will either"
            }
          ]
        },
        {
          "__type": "BulletList",
          "__tag": 4053,
          "ordered": false,
          "start": 1,
          "children": [
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "return a "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "masked array<maskedarray.generic>",
                      "domain": null,
                      "role": "ref",
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "   "
                    },
                    {
                      "__type": "Strong",
                      "__tag": 4048,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "masking out missing values"
                        }
                      ]
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " (if "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "usemask=True"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "), or"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Strong",
                      "__tag": 4048,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "fill in the missing value"
                        }
                      ]
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " with the value specified in   "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "filling_values"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " (default is "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "np.nan"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " for float, -1 for int)."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "With missing values"
        }
      ],
      "level": 2,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> with open(\"csv.txt\", \"r\") as f:\n...     print(f.read())\n1, 2, 3\n4,, 6\n7, 8, 9",
              "execution_status": null
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "With non-whitespace delimiters"
        }
      ],
      "level": 3,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> np.genfromtxt(\"csv.txt\", delimiter=\",\", usemask=True)\nmasked_array(\n  data=[[1.0, 2.0, 3.0],\n        [4.0, --, 6.0],\n        [7.0, 8.0, 9.0]],\n  mask=[[False, False, False],\n        [False,  True, False],\n        [False, False, False]],\n  fill_value=1e+20)",
              "execution_status": null
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Masked-array output"
        }
      ],
      "level": 4,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> np.genfromtxt(\"csv.txt\", delimiter=\",\")\narray([[ 1.,  2.,  3.],\n       [ 4., nan,  6.],\n       [ 7.,  8.,  9.]])",
              "execution_status": null
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Array output"
        }
      ],
      "level": 4,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> np.genfromtxt(\"csv.txt\", delimiter=\",\", dtype=np.int8, filling_values=99)\narray([[ 1,  2,  3],\n       [ 4, 99,  6],\n       [ 7,  8,  9]], dtype=int8)",
              "execution_status": null
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Array output, specified fill-in value"
        }
      ],
      "level": 4,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.genfromtxt",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy:genfromtxt"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " can also parse whitespace-delimited data files that have missing values if"
            }
          ]
        },
        {
          "__type": "BulletList",
          "__tag": 4053,
          "ordered": false,
          "start": 1,
          "children": [
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Strong",
                      "__tag": 4048,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "Each field has a fixed width"
                        }
                      ]
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ": Use the width as the "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "delimiter",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " argument.      "
                    }
                  ]
                },
                {
                  "__type": "Code",
                  "__tag": 4050,
                  "value": "# File with width=4. The data does not have to be justified (for example,\n# the 2 in row 1), the last column can be less than width (for example, the 6\n# in row 2), and no delimiting character is required (for instance 8888 and 9\n# in row 3)\n\n>>> with open(\"fixedwidth.txt\", \"r\") as f:\n...    data = (f.read())\n>>> print(data)\n1   2      3\n44      6\n7   88889\n\n# Showing spaces as ^\n>>> print(data.replace(\" \",\"^\"))\n1^^^2^^^^^^3\n44^^^^^^6\n7^^^88889\n\n>>> np.genfromtxt(\"fixedwidth.txt\", delimiter=4)\narray([[1.000e+00, 2.000e+00, 3.000e+00],\n       [4.400e+01,       nan, 6.000e+00],\n       [7.000e+00, 8.888e+03, 9.000e+00]])",
                  "execution_status": null
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Strong",
                      "__tag": 4048,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "A special value (e.g. \"x\") indicates a missing field"
                        }
                      ]
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ": Use it as the   "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "missing_values",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " argument."
                    }
                  ]
                },
                {
                  "__type": "Blockquote",
                  "__tag": 4059,
                  "children": [
                    {
                      "__type": "Code",
                      "__tag": 4050,
                      "value": ">>> with open(\"nan.txt\", \"r\") as f:\n...     print(f.read())\n1 2 3\n44 x 6\n7  8888 9",
                      "execution_status": null
                    },
                    {
                      "__type": "Code",
                      "__tag": 4050,
                      "value": ">>> np.genfromtxt(\"nan.txt\", missing_values=\"x\")\narray([[1.000e+00, 2.000e+00, 3.000e+00],\n       [4.400e+01,       nan, 6.000e+00],\n       [7.000e+00, 8.888e+03, 9.000e+00]])",
                      "execution_status": null
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Strong",
                      "__tag": 4048,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "You want to skip the rows with missing values"
                        }
                      ]
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ": Set   "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "invalid_raise=False",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                },
                {
                  "__type": "Blockquote",
                  "__tag": 4059,
                  "children": [
                    {
                      "__type": "Code",
                      "__tag": 4050,
                      "value": ">>> with open(\"skip.txt\", \"r\") as f:\n...     print(f.read())\n1 2   3\n44    6\n7 888 9",
                      "execution_status": null
                    },
                    {
                      "__type": "Code",
                      "__tag": 4050,
                      "value": ">>> np.genfromtxt(\"skip.txt\", invalid_raise=False)  # doctest: +SKIP\n__main__:1: ConversionWarning: Some errors were detected !\n    Line #2 (got 2 columns instead of 3)\narray([[  1.,   2.,   3.],\n       [  7., 888.,   9.]])",
                      "execution_status": null
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Strong",
                      "__tag": 4048,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "The delimiter whitespace character is different from the whitespace that\n  indicates missing data"
                        }
                      ]
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". For instance, if columns are delimited by "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "\\t"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ",   then missing data will be recognized if it consists of one   or more spaces.      "
                    }
                  ]
                },
                {
                  "__type": "Code",
                  "__tag": 4050,
                  "value": ">>> with open(\"tabs.txt\", \"r\") as f:\n...    data = (f.read())\n>>> print(data)\n1       2       3\n44              6\n7       888     9\n\n# Tabs vs. spaces\n>>> print(data.replace(\"\\t\",\"^\"))\n1^2^3\n44^ ^6\n7^888^9\n\n>>> np.genfromtxt(\"tabs.txt\", delimiter=\"\\t\", missing_values=\" +\")\narray([[  1.,   2.,   3.],\n       [ 44.,  nan,   6.],\n       [  7., 888.,   9.]])",
                  "execution_status": null
                }
              ]
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Whitespace-delimited"
        }
      ],
      "level": 3,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Choices:"
            }
          ]
        },
        {
          "__type": "BulletList",
          "__tag": 4053,
          "ordered": false,
          "start": 1,
          "children": [
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Use "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "numpy.load",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "numpy",
                        "version": "*",
                        "kind": "api",
                        "path": "numpy:load"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". It can read files generated by any of   "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "numpy.save",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "numpy",
                        "version": "*",
                        "kind": "api",
                        "path": "numpy:save"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "numpy.savez",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "numpy",
                        "version": "*",
                        "kind": "api",
                        "path": "numpy:savez"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", or "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "numpy.savez_compressed",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "numpy",
                        "version": "*",
                        "kind": "api",
                        "path": "numpy:savez_compressed"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Use memory mapping. See "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "numpy.lib.format.open_memmap",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "numpy",
                        "version": "*",
                        "kind": "api",
                        "path": "numpy.lib.format:open_memmap"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Read a file in .npy or .npz format"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Write to a file to be read back by NumPy"
        }
      ],
      "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.save",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy:save"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", or to store multiple arrays "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.savez",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy:savez"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " or "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.savez_compressed",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy:savez_compressed"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "For "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "security and portability",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "docs",
                "path": "user:how-to-io"
              },
              "kind": "exists"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", set "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "allow_pickle=False"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " unless the dtype contains Python objects, which requires pickling."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Masked arrays "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "can't currently be saved <MaskedArray.tofile>",
              "domain": null,
              "role": "any",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", nor can other arbitrary array subclasses."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Binary"
        }
      ],
      "level": 2,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.save",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy:save"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.savez",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy:savez"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " create binary files. To "
            },
            {
              "__type": "Strong",
              "__tag": 4048,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "write a\nhuman-readable file"
                }
              ]
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", use "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.savetxt",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy:savetxt"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". The array can only be 1- or 2-dimensional, and there's no "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "savetxtz"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " for multiple files."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Human-readable"
        }
      ],
      "level": 2,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "See "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "how-to-io-large-arrays",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "docs",
                "path": "user:how-to-io"
              },
              "kind": "exists"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Large arrays"
        }
      ],
      "level": 2,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Use a "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "structured array",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "docs",
                "path": "basics.rec"
              },
              "kind": "docs"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Strong",
              "__tag": 4048,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Example:"
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": ".wav"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " file header is a 44-byte block preceding "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "data_size"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " bytes of the actual sound data      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "chunk_id         \"RIFF\"\nchunk_size       4-byte unsigned little-endian integer\nformat           \"WAVE\"\nfmt_id           \"fmt \"\nfmt_size         4-byte unsigned little-endian integer\naudio_fmt        2-byte unsigned little-endian integer\nnum_channels     2-byte unsigned little-endian integer\nsample_rate      4-byte unsigned little-endian integer\nbyte_rate        4-byte unsigned little-endian integer\nblock_align      2-byte unsigned little-endian integer\nbits_per_sample  2-byte unsigned little-endian integer\ndata_id          \"data\"\ndata_size        4-byte unsigned little-endian integer",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": ".wav"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " file header as a NumPy structured dtype      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "wav_header_dtype = np.dtype([\n    (\"chunk_id\", (bytes, 4)), # flexible-sized scalar type, item size 4\n    (\"chunk_size\", \"<u4\"),    # little-endian unsigned 32-bit integer\n    (\"format\", \"S4\"),         # 4-byte string, alternate spelling of (bytes, 4)\n    (\"fmt_id\", \"S4\"),\n    (\"fmt_size\", \"<u4\"),\n    (\"audio_fmt\", \"<u2\"),     #\n    (\"num_channels\", \"<u2\"),  # .. more of the same ...\n    (\"sample_rate\", \"<u4\"),   #\n    (\"byte_rate\", \"<u4\"),\n    (\"block_align\", \"<u2\"),\n    (\"bits_per_sample\", \"<u2\"),\n    (\"data_id\", \"S4\"),\n    (\"data_size\", \"<u4\"),\n    #\n    # the sound data itself cannot be represented here:\n    # it does not have a fixed size\n])\n\nheader = np.fromfile(f, dtype=wave_header_dtype, count=1)[0]",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "This "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": ".wav"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " example is for illustration; to read a "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": ".wav"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " file in real life, use Python's built-in module "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "wave",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "wave",
                "version": "*",
                "kind": "api",
                "path": "wave"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "(Adapted from Pauli Virtanen, "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "advanced_numpy",
              "domain": null,
              "role": "ref",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", licensed under "
            },
            {
              "__type": "Link",
              "__tag": 4049,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "CC BY 4.0"
                }
              ],
              "url": "https://creativecommons.org/licenses/by/4.0/",
              "title": ""
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ".)"
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Read an arbitrarily formatted binary file (\"binary blob\")"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Strong",
              "__tag": 4048,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Arrays too large to fit in memory"
                }
              ]
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " can be treated like ordinary in-memory arrays using memory mapping."
            }
          ]
        },
        {
          "__type": "BulletList",
          "__tag": 4053,
          "ordered": false,
          "start": 1,
          "children": [
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Raw array data written with "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "numpy.ndarray.tofile",
                      "domain": null,
                      "role": "func",
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " or   "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "numpy.ndarray.tobytes",
                      "domain": null,
                      "role": "func",
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " can be read with "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "numpy.memmap",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "numpy",
                        "version": "*",
                        "kind": "api",
                        "path": "numpy:memmap"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ":        "
                    }
                  ]
                },
                {
                  "__type": "Code",
                  "__tag": 4050,
                  "value": "array = numpy.memmap(\"mydata/myarray.arr\", mode=\"r\", dtype=np.int16, shape=(1024, 1024))",
                  "execution_status": null
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Files output by "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "numpy.save",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "numpy",
                        "version": "*",
                        "kind": "api",
                        "path": "numpy:save"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " (that is, using the numpy format) can be read   using "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "numpy.load",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "numpy",
                        "version": "*",
                        "kind": "api",
                        "path": "numpy:load"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " with the "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "mmap_mode"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " keyword argument        "
                    }
                  ]
                },
                {
                  "__type": "Code",
                  "__tag": 4050,
                  "value": "large_array[some_slice] = np.load(\"path/to/small_array\", mmap_mode=\"r\")",
                  "execution_status": null
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Memory mapping lacks features like data chunking and compression; more full-featured formats and libraries usable with NumPy include:"
            }
          ]
        },
        {
          "__type": "BulletList",
          "__tag": 4053,
          "ordered": false,
          "start": 1,
          "children": [
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Strong",
                      "__tag": 4048,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "HDF5"
                        }
                      ]
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ": "
                    },
                    {
                      "__type": "Link",
                      "__tag": 4049,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "h5py"
                        }
                      ],
                      "url": "https://www.h5py.org/",
                      "title": ""
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " or "
                    },
                    {
                      "__type": "Link",
                      "__tag": 4049,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "PyTables"
                        }
                      ],
                      "url": "https://www.pytables.org/",
                      "title": ""
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Strong",
                      "__tag": 4048,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "Zarr"
                        }
                      ]
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ": "
                    },
                    {
                      "__type": "Link",
                      "__tag": 4049,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "here"
                        }
                      ],
                      "url": "https://zarr.readthedocs.io/en/stable/tutorial.html#reading-and-writing-data",
                      "title": ""
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Strong",
                      "__tag": 4048,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "NetCDF"
                        }
                      ]
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ": "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "scipy.io.netcdf_file",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "scipy",
                        "version": "*",
                        "kind": "api",
                        "path": "scipy.io._netcdf:netcdf_file"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "For tradeoffs among memmap, Zarr, and HDF5, see "
            },
            {
              "__type": "Link",
              "__tag": 4049,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "pythonspeed.com"
                }
              ],
              "url": "https://pythonspeed.com/articles/mmap-vs-zarr-hdf5/",
              "title": ""
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Write or read large arrays"
        }
      ],
      "level": 1,
      "target": "how-to-io-large-arrays"
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Formats for "
            },
            {
              "__type": "Strong",
              "__tag": 4048,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "exchanging data"
                }
              ]
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " with other tools include HDF5, Zarr, and NetCDF (see "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "how-to-io-large-arrays",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "docs",
                "path": "user:how-to-io"
              },
              "kind": "exists"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ")."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Write files for reading by other (non-NumPy) tools"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "NumPy arrays and most NumPy scalars are "
            },
            {
              "__type": "Strong",
              "__tag": 4048,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "not"
                }
              ]
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " directly "
            },
            {
              "__type": "Link",
              "__tag": 4049,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "JSON serializable"
                }
              ],
              "url": "https://github.com/numpy/numpy/issues/12481",
              "title": ""
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". Instead, use a custom "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "json.JSONEncoder",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "json",
                "version": "*",
                "kind": "api",
                "path": "json.encoder:JSONEncoder"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " for NumPy types, which can be found using your favorite search engine."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Write or read a JSON file"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Avoid when possible; "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "pickles",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "docs",
                "path": "python:library/pickle"
              },
              "kind": "docs"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " are not secure against erroneous or maliciously constructed data."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Use "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.save",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy:save"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.load",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy:load"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ".  Set "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "allow_pickle=False"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", unless the array dtype includes Python objects, in which case pickling is required."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.load",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy:load"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "pickle",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "pickle",
                "version": "*",
                "kind": "api",
                "path": "pickle"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " submodule also support unpickling files created with NumPy 1.26."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Save/restore using a pickle file"
        }
      ],
      "level": 1,
      "target": "how-to-io-pickle-file"
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "See "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "pandas.Series.to_numpy",
              "domain": null,
              "role": "meth",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Convert from a pandas DataFrame to a NumPy array"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "In general, prefer "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.save",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy:save"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.load",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy:load"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "numpy.ndarray.tofile",
              "domain": null,
              "role": "func",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.fromfile",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy:fromfile"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " lose information on endianness and precision and so are unsuitable for anything but scratch storage."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Save/restore using "
        },
        {
          "__type": "InlineRole",
          "__tag": 4003,
          "value": "~numpy.ndarray.tofile",
          "domain": null,
          "role": null,
          "inventory": null
        },
        {
          "__type": "Text",
          "__tag": 4046,
          "value": " and "
        },
        {
          "__type": "InlineRole",
          "__tag": 4003,
          "value": "~numpy.fromfile",
          "domain": null,
          "role": null,
          "inventory": null
        }
      ],
      "level": 1,
      "target": null
    }
  ],
  "local_refs": []
}