{
  "__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:basics.rec",
  "arbitrary": [
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Structured arrays"
        }
      ],
      "level": 0,
      "target": "structured_arrays"
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Structured arrays are ndarrays whose datatype is a composition of simpler datatypes organized as a sequence of named "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "fields <field>"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". For example, ::"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> x = np.array([('Rex', 9, 81.0), ('Fido', 3, 27.0)],\n...              dtype=[('name', 'U10'), ('age', 'i4'), ('weight', 'f4')])\n>>> x\narray([('Rex', 9, 81.), ('Fido', 3, 27.)],\n      dtype=[('name', '<U10'), ('age', '<i4'), ('weight', '<f4')])",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Here "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "x"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is a one-dimensional array of length two whose datatype is a structure with three fields: 1. A string of length 10 or less named 'name', 2. a 32-bit integer named 'age', and 3. a 32-bit float named 'weight'."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "If you index "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "x"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " at position 1 you get a structure   "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> x[1]\nnp.void(('Fido', 3, 27.0), dtype=[('name', '<U10'), ('age', '<i4'), ('weight', '<f4')])",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "You can access and modify individual fields of a structured array by indexing with the field name   "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> x['age']\narray([9, 3], dtype=int32)\n>>> x['age'] = 5\n>>> x\narray([('Rex', 5, 81.), ('Fido', 5, 27.)],\n      dtype=[('name', '<U10'), ('age', '<i4'), ('weight', '<f4')])",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Structured datatypes are designed to be able to mimic 'structs' in the C language, and share a similar memory layout. They are meant for interfacing with C code and for low-level manipulation of structured buffers, for example for interpreting binary blobs. For these purposes they support specialized features such as subarrays, nested datatypes, and unions, and allow control over the memory layout of the structure."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Users looking to manipulate tabular data, such as stored in csv files, may find other pydata projects more suitable, such as xarray, pandas, or DataArray. These provide a high-level interface for tabular data analysis and are better optimized for that use. For instance, the C-struct-like memory layout of structured arrays in numpy can lead to poor cache behavior in comparison."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Introduction"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "A structured datatype can be thought of as a sequence of bytes of a certain length (the structure's "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "itemsize"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ") which is interpreted as a collection of fields. Each field has a name, a datatype, and a byte offset within the structure. The datatype of a field may be any numpy datatype including other structured datatypes, and it may also be a "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "subarray data type"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " which behaves like an ndarray of a specified shape. The offsets of the fields are arbitrary, and fields may even overlap. These offsets are usually determined automatically by numpy, but can also be specified."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Structured datatypes"
        }
      ],
      "level": 1,
      "target": "defining-structured-types"
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Structured datatypes may be created using the function "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.dtype",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy:dtype"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". There are 4 alternative forms of specification which vary in flexibility and conciseness. These are further documented in the "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "Data Type Objects",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "docs",
                "path": "reference:arrays.dtypes"
              },
              "kind": "exists"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " reference page, and in summary they are:"
            }
          ]
        },
        {
          "__type": "BulletList",
          "__tag": 4053,
          "ordered": true,
          "start": 1,
          "children": [
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "A list of tuples, one tuple per field"
                    }
                  ]
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Each tuple has the form "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "(fieldname, datatype, shape)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " where shape is      optional. "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "fieldname"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is a string (or tuple if titles are used, see      "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "Field Titles",
                      "reference": {
                        "__type": "LocalRef",
                        "__tag": 4022,
                        "kind": "docs",
                        "path": "user:basics.rec"
                      },
                      "kind": "exists"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " below), "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "datatype"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " may be any object      convertible to a datatype, and "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "shape"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is a tuple of integers specifying      subarray shape."
                    }
                  ]
                },
                {
                  "__type": "Blockquote",
                  "__tag": 4059,
                  "children": [
                    {
                      "__type": "Code",
                      "__tag": 4050,
                      "value": ">>> np.dtype([('x', 'f4'), ('y', np.float32), ('z', 'f4', (2, 2))])\ndtype([('x', '<f4'), ('y', '<f4'), ('z', '<f4', (2, 2))])",
                      "execution_status": null
                    }
                  ]
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "If "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "fieldname"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is the empty string "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "''"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", the field will be given a      default name of the form "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "f#"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", where "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "#"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is the integer index of the      field, counting from 0 from the left        "
                    }
                  ]
                },
                {
                  "__type": "Code",
                  "__tag": 4050,
                  "value": ">>> np.dtype([('x', 'f4'), ('', 'i4'), ('z', 'i8')])\ndtype([('x', '<f4'), ('f1', '<i4'), ('z', '<i8')])",
                  "execution_status": null
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The byte offsets of the fields within the structure and the total      structure itemsize are determined automatically."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "A string of comma-separated dtype specifications"
                    }
                  ]
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "In this shorthand notation any of the "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "string dtype specifications",
                      "reference": {
                        "__type": "LocalRef",
                        "__tag": 4022,
                        "kind": "docs",
                        "path": "reference:arrays.dtypes"
                      },
                      "kind": "exists"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " may be used in a string and separated by      commas. The itemsize and byte offsets of the fields are determined      automatically, and the field names are given the default names "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "f0"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ",      "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "f1"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", etc.         "
                    }
                  ]
                },
                {
                  "__type": "Code",
                  "__tag": 4050,
                  "value": ">>> np.dtype('i8, f4, S3')\ndtype([('f0', '<i8'), ('f1', '<f4'), ('f2', 'S3')])\n>>> np.dtype('3int8, float32, (2, 3)float64')\ndtype([('f0', 'i1', (3,)), ('f1', '<f4'), ('f2', '<f8', (2, 3))])",
                  "execution_status": null
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "A dictionary of field parameter arrays"
                    }
                  ]
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "This is the most flexible form of specification since it allows control      over the byte-offsets of the fields and the itemsize of the structure."
                    }
                  ]
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The dictionary has two required keys, 'names' and 'formats', and four      optional keys, 'offsets', 'itemsize', 'aligned' and 'titles'. The values      for 'names' and 'formats' should respectively be a list of field names and      a list of dtype specifications, of the same length. The optional 'offsets'      value should be a list of integer byte-offsets, one for each field within      the structure. If 'offsets' is not given the offsets are determined      automatically. The optional 'itemsize' value should be an integer      describing the total size in bytes of the dtype, which must be large      enough to contain all the fields.      ::"
                    }
                  ]
                },
                {
                  "__type": "Blockquote",
                  "__tag": 4059,
                  "children": [
                    {
                      "__type": "Code",
                      "__tag": 4050,
                      "value": ">>> np.dtype({'names': ['col1', 'col2'], 'formats': ['i4', 'f4']})\ndtype([('col1', '<i4'), ('col2', '<f4')])\n>>> np.dtype({'names': ['col1', 'col2'],\n...           'formats': ['i4', 'f4'],\n...           'offsets': [0, 4],\n...           'itemsize': 12})\ndtype({'names': ['col1', 'col2'], 'formats': ['<i4', '<f4'], 'offsets': [0, 4], 'itemsize': 12})",
                      "execution_status": null
                    }
                  ]
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Offsets may be chosen such that the fields overlap, though this will mean      that assigning to one field may clobber any overlapping field's data. As      an exception, fields of "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "numpy.object_",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "numpy",
                        "version": "*",
                        "kind": "api",
                        "path": "numpy:object_"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " type cannot overlap with      other fields, because of the risk of clobbering the internal object      pointer and then dereferencing it."
                    }
                  ]
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The optional 'aligned' value can be set to "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "True"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " to make the automatic      offset computation use aligned offsets (see "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "offsets-and-alignment",
                      "reference": {
                        "__type": "LocalRef",
                        "__tag": 4022,
                        "kind": "docs",
                        "path": "user:basics.rec"
                      },
                      "kind": "exists"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "),      as if the 'align' keyword argument of "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "numpy.dtype",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "numpy",
                        "version": "*",
                        "kind": "api",
                        "path": "numpy:dtype"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " had been set to      True."
                    }
                  ]
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The optional 'titles' value should be a list of titles of the same length      as 'names', see "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "Field Titles",
                      "reference": {
                        "__type": "LocalRef",
                        "__tag": 4022,
                        "kind": "docs",
                        "path": "user:basics.rec"
                      },
                      "kind": "exists"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " below."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "A dictionary of field names"
                    }
                  ]
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The keys of the dictionary are the field names and the values are tuples      specifying type and offset        "
                    }
                  ]
                },
                {
                  "__type": "Code",
                  "__tag": 4050,
                  "value": ">>> np.dtype({'col1': ('i1', 0), 'col2': ('f4', 1)})\ndtype([('col1', 'i1'), ('col2', '<f4')])",
                  "execution_status": null
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "This form was discouraged because Python dictionaries did not preserve order      in Python versions before Python 3.6. "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "Field Titles",
                      "reference": {
                        "__type": "LocalRef",
                        "__tag": 4022,
                        "kind": "docs",
                        "path": "user:basics.rec"
                      },
                      "kind": "exists"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " may be      specified by using a 3-tuple, see below."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Structured datatype creation"
        }
      ],
      "level": 2,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The list of field names of a structured datatype can be found in the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "names"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " attribute of the dtype object   "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> d = np.dtype([('x', 'i8'), ('y', 'f4')])\n>>> d.names\n('x', 'y')",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The dtype of each individual field can be looked up by name   "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> d['x']\ndtype('int64')",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The field names may be modified by assigning to the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "names"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " attribute using a sequence of strings of the same length."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The dtype object also has a dictionary-like attribute, "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "fields"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", whose keys are the field names (and "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "Field Titles",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "docs",
                "path": "user:basics.rec"
              },
              "kind": "exists"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", see below) and whose values are tuples containing the dtype and byte offset of each field.    "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> d.fields\nmappingproxy({'x': (dtype('int64'), 0), 'y': (dtype('float32'), 8)})",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Both the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "names"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "fields"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " attributes will equal "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "None"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " for unstructured arrays. The recommended way to test if a dtype is structured is with "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "if dt.names is not None",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " rather than "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "if dt.names",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", to account for dtypes with 0 fields."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The string representation of a structured datatype is shown in the \"list of tuples\" form if possible, otherwise numpy falls back to using the more general dictionary form."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Manipulating and displaying structured datatypes"
        }
      ],
      "level": 2,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Numpy uses one of two methods to automatically determine the field byte offsets and the overall itemsize of a structured datatype, depending on whether "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "align=True"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " was specified as a keyword argument to "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.dtype",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy:dtype"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "By default ("
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "align=False"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "), numpy will pack the fields together such that each field starts at the byte offset the previous field ended, and the fields are contiguous in memory.    "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> def print_offsets(d):\n...     print(\"offsets:\", [d.fields[name][1] for name in d.names])\n...     print(\"itemsize:\", d.itemsize)\n>>> print_offsets(np.dtype('u1, u1, i4, u1, i8, u2'))\noffsets: [0, 1, 2, 6, 7, 15]\nitemsize: 17",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "If "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "align=True"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is set, numpy will pad the structure in the same way many C compilers would pad a C-struct. Aligned structures can give a performance improvement in some cases, at the cost of increased datatype size. Padding bytes are inserted between fields such that each field's byte offset will be a multiple of that field's alignment, which is usually equal to the field's size in bytes for simple datatypes, see "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "PyArray_Descr.alignment"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ".  The structure will also have trailing padding added so that its itemsize is a multiple of the largest field's alignment.    "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> print_offsets(np.dtype('u1, u1, i4, u1, i8, u2', align=True))\noffsets: [0, 1, 4, 8, 16, 24]\nitemsize: 32",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Note that although almost all modern C compilers pad in this way by default, padding in C structs is C-implementation-dependent so this memory layout is not guaranteed to exactly match that of a corresponding struct in a C program. Some work may be needed, either on the numpy side or the C side, to obtain exact correspondence."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "If offsets were specified using the optional "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "offsets"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " key in the dictionary-based dtype specification, setting "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "align=True"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " will check that each field's offset is a multiple of its size and that the itemsize is a multiple of the largest field size, and raise an exception if not."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "If the offsets of the fields and itemsize of a structured array satisfy the alignment conditions, the array will have the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "ALIGNED"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "flag <numpy.ndarray.flags>",
              "domain": null,
              "role": "attr",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " set."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "A convenience function "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.lib.recfunctions.repack_fields",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy.lib.recfunctions:repack_fields"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " converts an aligned dtype or array to a packed one and vice versa. It takes either a dtype or structured ndarray as an argument, and returns a copy with fields re-packed, with or without padding bytes."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Automatic byte offsets and alignment"
        }
      ],
      "level": 2,
      "target": "offsets-and-alignment"
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "In addition to field names, fields may also have an associated "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "title"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", an alternate name, which is sometimes used as an additional description or alias for the field. The title may be used to index an array, just like a field name."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "To add titles when using the list-of-tuples form of dtype specification, the field name may be specified as a tuple of two strings instead of a single string, which will be the field's title and field name respectively. For example   "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> np.dtype([(('my title', 'name'), 'f4')])\ndtype([(('my title', 'name'), '<f4')])",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "When using the first form of dictionary-based specification, the titles may be supplied as an extra "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "'titles'"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " key as described above. When using the second (discouraged) dictionary-based specification, the title can be supplied by providing a 3-element tuple "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "(datatype, offset, title)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " instead of the usual 2-element tuple   "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> np.dtype({'name': ('i4', 0, 'my title')})\ndtype([(('my title', 'name'), '<i4')])",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "dtype.fields"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " dictionary will contain titles as keys, if any titles are used.  This means effectively that a field with a title will be represented twice in the fields dictionary. The tuple values for these fields will also have a third element, the field title. Because of this, and because the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "names"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " attribute preserves the field order while the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "fields"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " attribute may not, it is recommended to iterate through the fields of a dtype using the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "names"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " attribute of the dtype, which will not list titles, as in   "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> for name in d.names:\n...     print(d.fields[name][:2])\n(dtype('int64'), 0)\n(dtype('float32'), 8)",
          "execution_status": null
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Field titles"
        }
      ],
      "level": 2,
      "target": "titles"
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Structured datatypes are implemented in numpy to have base type "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.void",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy:void"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " by default, but it is possible to interpret other numpy types as structured types using the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "(base_dtype, dtype)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " form of dtype specification described in "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "Data Type Objects",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "docs",
                "path": "reference:arrays.dtypes"
              },
              "kind": "exists"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ".  Here, "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "base_dtype"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is the desired underlying dtype, and fields and flags will be copied from "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "dtype"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". This dtype is similar to a 'union' in C."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Union types"
        }
      ],
      "level": 2,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Indexing and assignment to structured arrays"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "There are a number of ways to assign values to a structured array: Using python tuples, using scalar values, or using other structured arrays."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Assigning data to a structured array"
        }
      ],
      "level": 2,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The simplest way to assign values to a structured array is using python tuples. Each assigned value should be a tuple of length equal to the number of fields in the array, and not a list or array as these will trigger numpy's broadcasting rules. The tuple's elements are assigned to the successive fields of the array, from left to right   "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> x = np.array([(1, 2, 3), (4, 5, 6)], dtype='i8, f4, f8')\n>>> x[1] = (7, 8, 9)\n>>> x\narray([(1, 2., 3.), (7, 8., 9.)],\n     dtype=[('f0', '<i8'), ('f1', '<f4'), ('f2', '<f8')])",
          "execution_status": null
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Assignment from Python Native Types (Tuples)"
        }
      ],
      "level": 3,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "A scalar assigned to a structured element will be assigned to all fields. This happens when a scalar is assigned to a structured array, or when an unstructured array is assigned to a structured array   "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> x = np.zeros(2, dtype='i8, f4, ?, S1')\n>>> x[:] = 3\n>>> x\narray([(3, 3., True, b'3'), (3, 3., True, b'3')],\n      dtype=[('f0', '<i8'), ('f1', '<f4'), ('f2', '?'), ('f3', 'S1')])\n>>> x[:] = np.arange(2)\n>>> x\narray([(0, 0., False, b'0'), (1, 1., True, b'1')],\n      dtype=[('f0', '<i8'), ('f1', '<f4'), ('f2', '?'), ('f3', 'S1')])",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Structured arrays can also be assigned to unstructured arrays, but only if the structured datatype has just a single field   "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> twofield = np.zeros(2, dtype=[('A', 'i4'), ('B', 'i4')])\n>>> onefield = np.zeros(2, dtype=[('A', 'i4')])\n>>> nostruct = np.zeros(2, dtype='i4')\n>>> nostruct[:] = twofield\nTraceback (most recent call last):\n...\nTypeError: Cannot cast array data from dtype([('A', '<i4'), ('B', '<i4')]) to dtype('int32') according to the rule 'unsafe'",
          "execution_status": null
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Assignment from Scalars"
        }
      ],
      "level": 3,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Assignment between two structured arrays occurs as if the source elements had been converted to tuples and then assigned to the destination elements. That is, the first field of the source array is assigned to the first field of the destination array, and the second field likewise, and so on, regardless of field names. Structured arrays with a different number of fields cannot be assigned to each other. Bytes of the destination structure which are not included in any of the fields are unaffected.    "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> a = np.zeros(3, dtype=[('a', 'i8'), ('b', 'f4'), ('c', 'S3')])\n>>> b = np.ones(3, dtype=[('x', 'f4'), ('y', 'S3'), ('z', 'O')])\n>>> b[:] = a\n>>> b\narray([(0., b'0.0', b''), (0., b'0.0', b''), (0., b'0.0', b'')],\n      dtype=[('x', '<f4'), ('y', 'S3'), ('z', 'O')])",
          "execution_status": null
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Assignment from other Structured Arrays"
        }
      ],
      "level": 3,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "When assigning to fields which are subarrays, the assigned value will first be broadcast to the shape of the subarray."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Assignment involving subarrays"
        }
      ],
      "level": 3,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Indexing structured arrays"
        }
      ],
      "level": 2,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Individual fields of a structured array may be accessed and modified by indexing the array with the field name.    "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> x = np.array([(1, 2), (3, 4)], dtype=[('foo', 'i8'), ('bar', 'f4')])\n>>> x['foo']\narray([1, 3])\n>>> x['foo'] = 10\n>>> x\narray([(10, 2.), (10, 4.)],\n      dtype=[('foo', '<i8'), ('bar', '<f4')])",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The resulting array is a view into the original array. It shares the same memory locations and writing to the view will modify the original array.    "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> y = x['bar']\n>>> y[:] = 11\n>>> x\narray([(10, 11.), (10, 11.)],\n      dtype=[('foo', '<i8'), ('bar', '<f4')])",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "This view has the same dtype and itemsize as the indexed field, so it is typically a non-structured array, except in the case of nested structures."
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> y.dtype, y.shape, y.strides\n(dtype('float32'), (2,), (12,))",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "If the accessed field is a subarray, the dimensions of the subarray are appended to the shape of the result     "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> x = np.zeros((2, 2), dtype=[('a', np.int32), ('b', np.float64, (3, 3))])\n>>> x['a'].shape\n(2, 2)\n>>> x['b'].shape\n(2, 2, 3, 3)",
          "execution_status": null
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Accessing Individual Fields"
        }
      ],
      "level": 3,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "One can index and assign to a structured array with a multi-field index, where the index is a list of field names."
            }
          ]
        },
        {
          "__type": "Admonition",
          "__tag": 4056,
          "kind": "warning",
          "base_type": "warning",
          "children": [
            {
              "__type": "AdmonitionTitle",
              "__tag": 4055,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "warning "
                }
              ]
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "The behavior of multi-field indexes changed from Numpy 1.15 to Numpy 1.16."
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The result of indexing with a multi-field index is a view into the original array, as follows   "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> a = np.zeros(3, dtype=[('a', 'i4'), ('b', 'i4'), ('c', 'f4')])\n>>> a[['a', 'c']]\narray([(0, 0.), (0, 0.), (0, 0.)],\n     dtype={'names': ['a', 'c'], 'formats': ['<i4', '<f4'], 'offsets': [0, 8], 'itemsize': 12})",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Assignment to the view modifies the original array. The view's fields will be in the order they were indexed. Note that unlike for single-field indexing, the dtype of the view has the same itemsize as the original array, and has fields at the same offsets as in the original array, and unindexed fields are merely missing."
            }
          ]
        },
        {
          "__type": "Admonition",
          "__tag": 4056,
          "kind": "warning",
          "base_type": "warning",
          "children": [
            {
              "__type": "AdmonitionTitle",
              "__tag": 4055,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "warning "
                }
              ]
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "In Numpy 1.15, indexing an array with a multi-field index returned a copy of the result above, but with fields packed together in memory as if passed through "
                },
                {
                  "__type": "CrossRef",
                  "__tag": 4002,
                  "value": "numpy.lib.recfunctions.repack_fields",
                  "reference": {
                    "__type": "RefInfo",
                    "__tag": 4000,
                    "module": "numpy",
                    "version": "*",
                    "kind": "api",
                    "path": "numpy.lib.recfunctions:repack_fields"
                  },
                  "kind": "module"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "."
                }
              ]
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "The new behavior as of Numpy 1.16 leads to extra \"padding\" bytes at the location of unindexed fields compared to 1.15. You will need to update any code which depends on the data having a \"packed\" layout. For instance code such as   "
                }
              ]
            },
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> a[['a', 'c']].view('i8')  # Fails in Numpy 1.16\nTraceback (most recent call last):\n   File \"<stdin>\", line 1, in <module>\nValueError: When changing to a smaller dtype, its size must be a divisor of the size of original dtype",
              "execution_status": null
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "will need to be changed. This code has raised a "
                },
                {
                  "__type": "InlineCode",
                  "__tag": 4051,
                  "value": "FutureWarning"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " since Numpy 1.12, and similar code has raised "
                },
                {
                  "__type": "InlineCode",
                  "__tag": 4051,
                  "value": "FutureWarning"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " since 1.7."
                }
              ]
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "In 1.16 a number of functions have been introduced in the "
                },
                {
                  "__type": "CrossRef",
                  "__tag": 4002,
                  "value": "numpy.lib.recfunctions",
                  "reference": {
                    "__type": "RefInfo",
                    "__tag": 4000,
                    "module": "numpy",
                    "version": "*",
                    "kind": "api",
                    "path": "numpy.lib.recfunctions"
                  },
                  "kind": "module"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " module to help users account for this change. These are "
                },
                {
                  "__type": "CrossRef",
                  "__tag": 4002,
                  "value": "numpy.lib.recfunctions.repack_fields",
                  "reference": {
                    "__type": "RefInfo",
                    "__tag": 4000,
                    "module": "numpy",
                    "version": "*",
                    "kind": "api",
                    "path": "numpy.lib.recfunctions:repack_fields"
                  },
                  "kind": "module"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": ". "
                },
                {
                  "__type": "CrossRef",
                  "__tag": 4002,
                  "value": "numpy.lib.recfunctions.structured_to_unstructured",
                  "reference": {
                    "__type": "RefInfo",
                    "__tag": 4000,
                    "module": "numpy",
                    "version": "*",
                    "kind": "api",
                    "path": "numpy.lib.recfunctions:structured_to_unstructured"
                  },
                  "kind": "module"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": ", "
                },
                {
                  "__type": "CrossRef",
                  "__tag": 4002,
                  "value": "numpy.lib.recfunctions.unstructured_to_structured",
                  "reference": {
                    "__type": "RefInfo",
                    "__tag": 4000,
                    "module": "numpy",
                    "version": "*",
                    "kind": "api",
                    "path": "numpy.lib.recfunctions:unstructured_to_structured"
                  },
                  "kind": "module"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": ", "
                },
                {
                  "__type": "CrossRef",
                  "__tag": 4002,
                  "value": "numpy.lib.recfunctions.apply_along_fields",
                  "reference": {
                    "__type": "RefInfo",
                    "__tag": 4000,
                    "module": "numpy",
                    "version": "*",
                    "kind": "api",
                    "path": "numpy.lib.recfunctions:apply_along_fields"
                  },
                  "kind": "module"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": ", "
                },
                {
                  "__type": "CrossRef",
                  "__tag": 4002,
                  "value": "numpy.lib.recfunctions.assign_fields_by_name",
                  "reference": {
                    "__type": "RefInfo",
                    "__tag": 4000,
                    "module": "numpy",
                    "version": "*",
                    "kind": "api",
                    "path": "numpy.lib.recfunctions:assign_fields_by_name"
                  },
                  "kind": "module"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": ",  and "
                },
                {
                  "__type": "CrossRef",
                  "__tag": 4002,
                  "value": "numpy.lib.recfunctions.require_fields",
                  "reference": {
                    "__type": "RefInfo",
                    "__tag": 4000,
                    "module": "numpy",
                    "version": "*",
                    "kind": "api",
                    "path": "numpy.lib.recfunctions:require_fields"
                  },
                  "kind": "module"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "."
                }
              ]
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "The function "
                },
                {
                  "__type": "CrossRef",
                  "__tag": 4002,
                  "value": "numpy.lib.recfunctions.repack_fields",
                  "reference": {
                    "__type": "RefInfo",
                    "__tag": 4000,
                    "module": "numpy",
                    "version": "*",
                    "kind": "api",
                    "path": "numpy.lib.recfunctions:repack_fields"
                  },
                  "kind": "module"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " can always be used to reproduce the old behavior, as it will return a packed copy of the structured array. The code above, for example, can be replaced with:"
                }
              ]
            },
            {
              "__type": "Blockquote",
              "__tag": 4059,
              "children": [
                {
                  "__type": "Code",
                  "__tag": 4050,
                  "value": ">>> from numpy.lib.recfunctions import repack_fields\n>>> repack_fields(a[['a', 'c']]).view('i8')  # supported in 1.16\narray([0, 0, 0])",
                  "execution_status": null
                }
              ]
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Furthermore, numpy now provides a new function "
                },
                {
                  "__type": "CrossRef",
                  "__tag": 4002,
                  "value": "numpy.lib.recfunctions.structured_to_unstructured",
                  "reference": {
                    "__type": "RefInfo",
                    "__tag": 4000,
                    "module": "numpy",
                    "version": "*",
                    "kind": "api",
                    "path": "numpy.lib.recfunctions:structured_to_unstructured"
                  },
                  "kind": "module"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " which is a safer and more efficient alternative for users who wish to convert structured arrays to unstructured arrays, as the view above is often intended to do. This function allows safe conversion to an unstructured type taking into account padding, often avoids a copy, and also casts the datatypes as needed, unlike the view. Code such as:"
                }
              ]
            },
            {
              "__type": "Blockquote",
              "__tag": 4059,
              "children": [
                {
                  "__type": "Code",
                  "__tag": 4050,
                  "value": ">>> b = np.zeros(3, dtype=[('x', 'f4'), ('y', 'f4'), ('z', 'f4')])\n>>> b[['x', 'z']].view('f4')\narray([0., 0., 0., 0., 0., 0., 0., 0., 0.], dtype=float32)",
                  "execution_status": null
                }
              ]
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "can be made safer by replacing with:"
                }
              ]
            },
            {
              "__type": "Blockquote",
              "__tag": 4059,
              "children": [
                {
                  "__type": "Code",
                  "__tag": 4050,
                  "value": ">>> from numpy.lib.recfunctions import structured_to_unstructured\n>>> structured_to_unstructured(b[['x', 'z']])\narray([[0., 0.],\n       [0., 0.],\n       [0., 0.]], dtype=float32)",
                  "execution_status": null
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Assignment to an array with a multi-field index modifies the original array   "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> a[['a', 'c']] = (2, 3)\n>>> a\narray([(2, 0, 3.), (2, 0, 3.), (2, 0, 3.)],\n      dtype=[('a', '<i4'), ('b', '<i4'), ('c', '<f4')])",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "This obeys the structured array assignment rules described above. For example, this means that one can swap the values of two fields using appropriate multi-field indexes   "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> a[['a', 'c']] = a[['c', 'a']]",
          "execution_status": null
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Accessing Multiple Fields"
        }
      ],
      "level": 3,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Indexing a single element of a structured array (with an integer index) returns a structured scalar   "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> x = np.array([(1, 2., 3.)], dtype='i, f, f')\n>>> scalar = x[0]\n>>> scalar\nnp.void((1, 2.0, 3.0), dtype=[('f0', '<i4'), ('f1', '<f4'), ('f2', '<f4')])\n>>> type(scalar)\n<class 'numpy.void'>",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Unlike other numpy scalars, structured scalars are mutable and act like views into the original array, such that modifying the scalar will modify the original array. Structured scalars also support access and assignment by field name   "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> x = np.array([(1, 2), (3, 4)], dtype=[('foo', 'i8'), ('bar', 'f4')])\n>>> s = x[0]\n>>> s['bar'] = 100\n>>> x\narray([(1, 100.), (3, 4.)],\n      dtype=[('foo', '<i8'), ('bar', '<f4')])",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Similarly to tuples, structured scalars can also be indexed with an integer   "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> scalar = np.array([(1, 2., 3.)], dtype='i, f, f')[0]\n>>> scalar[0]\nnp.int32(1)\n>>> scalar[1] = 4",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Thus, tuples might be thought of as the native Python equivalent to numpy's structured types, much like native python integers are the equivalent to numpy's integer types. Structured scalars may be converted to a tuple by calling "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "numpy.ndarray.item",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ":   "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> scalar.item(), type(scalar.item())\n((1, 4.0, 3.0), <class 'tuple'>)",
          "execution_status": null
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Indexing with an Integer to get a Structured Scalar"
        }
      ],
      "level": 3,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "In order to prevent clobbering object pointers in fields of "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "object",
              "domain": null,
              "role": "class",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " type, numpy currently does not allow views of structured arrays containing objects."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Viewing structured arrays containing objects"
        }
      ],
      "level": 2,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "If the dtypes of two void structured arrays are equal, testing the equality of the arrays will result in a boolean array with the dimensions of the original arrays, with elements set to "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "True"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " where all fields of the corresponding structures are equal   "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> a = np.array([(1, 1), (2, 2)], dtype=[('a', 'i4'), ('b', 'i4')])\n>>> b = np.array([(1, 1), (2, 3)], dtype=[('a', 'i4'), ('b', 'i4')])\n>>> a == b\narray([True, False])",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "NumPy will promote individual field datatypes to perform the comparison. So the following is also valid (note the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "'f4'"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " dtype for the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "'a'"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " field):"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> b = np.array([(1.0, 1), (2.5, 2)], dtype=[(\"a\", \"f4\"), (\"b\", \"i4\")])\n>>> a == b\narray([True, False])",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "To compare two structured arrays, it must be possible to promote them to a common dtype as returned by "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.result_type",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy:result_type"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.promote_types",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy:promote_types"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". This enforces that the number of fields, the field names, and the field titles must match precisely. When promotion is not possible, for example due to mismatching field names, NumPy will raise an error. Promotion between two structured dtypes results in a canonical dtype that ensures native byte-order for all fields      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> np.result_type(np.dtype(\"i,>i\"))\ndtype([('f0', '<i4'), ('f1', '<i4')])\n>>> np.result_type(np.dtype(\"i,>i\"), np.dtype(\"i,i\"))\ndtype([('f0', '<i4'), ('f1', '<i4')])",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The resulting dtype from promotion is also guaranteed to be packed, meaning that all fields are ordered contiguously and any unnecessary padding is removed      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> dt = np.dtype(\"i1,V3,i4,V1\")[[\"f0\", \"f2\"]]\n>>> dt\ndtype({'names': ['f0', 'f2'], 'formats': ['i1', '<i4'], 'offsets': [0, 4], 'itemsize': 9})\n>>> np.result_type(dt)\ndtype([('f0', 'i1'), ('f2', '<i4')])",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Note that the result prints without "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "offsets"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " or "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "itemsize"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " indicating no additional padding. If a structured dtype is created with "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "align=True"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " ensuring that "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "dtype.isalignedstruct"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is true, this property is preserved      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> dt = np.dtype(\"i1,V3,i4,V1\", align=True)[[\"f0\", \"f2\"]]\n>>> dt\ndtype({'names': ['f0', 'f2'], 'formats': ['i1', '<i4'], 'offsets': [0, 4], 'itemsize': 12}, align=True)\n\n>>> np.result_type(dt)\ndtype([('f0', 'i1'), ('f2', '<i4')], align=True)\n>>> np.result_type(dt).isalignedstruct\nTrue",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "When promoting multiple dtypes, the result is aligned if any of the inputs is      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> np.result_type(np.dtype(\"i,i\"), np.dtype(\"i,i\", align=True))\ndtype([('f0', '<i4'), ('f1', '<i4')], align=True)",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "<"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": ">"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " operators always return "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "False"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " when comparing void structured arrays, and arithmetic and bitwise operations are not supported."
            }
          ]
        },
        {
          "__type": "Admonition",
          "__tag": 4056,
          "kind": "versionchanged",
          "base_type": "neutral",
          "children": [
            {
              "__type": "AdmonitionTitle",
              "__tag": 4055,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "versionchanged 1.23"
                }
              ]
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Before NumPy 1.23, a warning was given and "
                },
                {
                  "__type": "InlineCode",
                  "__tag": 4051,
                  "value": "False"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " returned when promotion to a common dtype failed. Further, promotion was much more restrictive: It would reject the mixed float/integer comparison example above."
                }
              ]
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Structure comparison and promotion"
        }
      ],
      "level": 2,
      "target": "structured_dtype_comparison_and_promotion"
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "As an optional convenience numpy provides an ndarray subclass, "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.recarray",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy.rec:recarray"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " that allows access to fields of structured arrays by attribute instead of only by index. Record arrays use a special datatype, "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.record",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy:record"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", that allows field access by attribute on the structured scalars obtained from the array. The "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "numpy.rec"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " module provides functions for creating recarrays from various objects. Additional helper functions for creating and manipulating structured arrays can be found in "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.lib.recfunctions",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy.lib.recfunctions"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The simplest way to create a record array is with "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "numpy.rec.array <numpy.rec.array>",
              "domain": null,
              "role": "func",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ":   "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> recordarr = np.rec.array([(1, 2., 'Hello'), (2, 3., \"World\")],\n...                    dtype=[('foo', 'i4'),('bar', 'f4'), ('baz', 'S10')])\n>>> recordarr.bar\narray([2., 3.], dtype=float32)\n>>> recordarr[1:2]\nrec.array([(2, 3., b'World')],\n      dtype=[('foo', '<i4'), ('bar', '<f4'), ('baz', 'S10')])\n>>> recordarr[1:2].foo\narray([2], dtype=int32)\n>>> recordarr.foo[1:2]\narray([2], dtype=int32)\n>>> recordarr[1].baz\nb'World'",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "numpy.rec.array <numpy.rec.array>",
              "domain": null,
              "role": "func",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " can convert a wide variety of arguments into record arrays, including structured arrays   "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> arr = np.array([(1, 2., 'Hello'), (2, 3., \"World\")],\n...             dtype=[('foo', 'i4'), ('bar', 'f4'), ('baz', 'S10')])\n>>> recordarr = np.rec.array(arr)",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "numpy.rec"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " module provides a number of other convenience functions for creating record arrays, see "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "record array creation routines",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "docs",
                "path": "reference:routines.array-creation"
              },
              "kind": "exists"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "A record array representation of a structured array can be obtained using the appropriate "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "view <numpy.ndarray.view>",
              "domain": null,
              "role": "meth",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ":   "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> arr = np.array([(1, 2., 'Hello'), (2, 3., \"World\")],\n...                dtype=[('foo', 'i4'),('bar', 'f4'), ('baz', 'S10')])\n>>> recordarr = arr.view(dtype=np.dtype((np.record, arr.dtype)),\n...                      type=np.recarray)",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "For convenience, viewing an ndarray as type "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.recarray",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy.rec:recarray"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " will automatically convert to "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.record",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy:record"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " datatype, so the dtype can be left out of the view   "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> recordarr = arr.view(np.recarray)\n>>> recordarr.dtype\ndtype((numpy.record, [('foo', '<i4'), ('bar', '<f4'), ('baz', 'S10')]))",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "To get back to a plain ndarray both the dtype and type must be reset. The following view does so, taking into account the unusual case that the recordarr was not a structured type   "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> arr2 = recordarr.view(recordarr.dtype.fields or recordarr.dtype, np.ndarray)",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Record array fields accessed by index or by attribute are returned as a record array if the field has a structured type but as a plain ndarray otherwise.    "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> recordarr = np.rec.array([('Hello', (1, 2)), (\"World\", (3, 4))],\n...                 dtype=[('foo', 'S6'),('bar', [('A', int), ('B', int)])])\n>>> type(recordarr.foo)\n<class 'numpy.ndarray'>\n>>> type(recordarr.bar)\n<class 'numpy.rec.recarray'>",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Note that if a field has the same name as an ndarray attribute, the ndarray attribute takes precedence. Such fields will be inaccessible by attribute but will still be accessible by index."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Record arrays"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Recarray helper functions"
        }
      ],
      "level": 2,
      "target": null
    }
  ],
  "local_refs": []
}