# numpy 2.5.4 (BSD-3-Clause), harvested by tools/harvest_corpus.py
=== input

    Construct an array from a text file, using regular expression parsing.

    The returned array is always a structured array, and is constructed from
    all matches of the regular expression in the file. Groups in the regular
    expression are converted to fields of the structured array.

    Parameters
    ----------
    file : file, str, or pathlib.Path
        Filename or file object to read.

        .. versionchanged:: 1.22.0
            Now accepts `os.PathLike` implementations.

    regexp : str or regexp
        Regular expression used to parse the file.
        Groups in the regular expression correspond to fields in the dtype.
    dtype : dtype or list of dtypes
        Dtype for the structured array; must be a structured datatype.
    encoding : str, optional
        Encoding used to decode the inputfile. Does not apply to input streams.

    Returns
    -------
    output : ndarray
        The output array, containing the part of the content of `file` that
        was matched by `regexp`. `output` is always a structured array.

    Raises
    ------
    TypeError
        When `dtype` is not a valid dtype for a structured array.

    See Also
    --------
    fromstring, loadtxt

    Notes
    -----
    Dtypes for structured arrays can be specified in several forms, but all
    forms specify at least the data type and field name. For details see
    `basics.rec`.

    Examples
    --------
    >>> import numpy as np
    >>> from io import StringIO
    >>> text = StringIO("1312 foo\n1534  bar\n444   qux")

    >>> regexp = r"(\d+)\s+(...)"  # match [digits, whitespace, anything]
    >>> output = np.fromregex(text, regexp,
    ...                       [('num', np.int64), ('key', 'S3')])
    >>> output
    array([(1312, b'foo'), (1534, b'bar'), ( 444, b'qux')],
          dtype=[('num', '<i8'), ('key', 'S3')])
    >>> output['num']
    array([1312, 1534,  444])

    
=== parse numpydoc
short_description: 'Construct an array from a text file, using regular expression parsing.'
long_description: |
  The returned array is always a structured array, and is constructed from
  all matches of the regular expression in the file. Groups in the regular
  expression are converted to fields of the structured array.
blank_after_short_description: True
blank_after_long_description: True
style: numpydoc
- DocstringParam
  description: |
    Filename or file object to read.
    
    .. versionchanged:: 1.22.0
        Now accepts `os.PathLike` implementations.
  kind: param
  key: 'param'
  arg_name: 'file'
  type_name: 'file, str, or pathlib.Path'
  is_optional: False
- DocstringParam
  description: |
    Regular expression used to parse the file.
    Groups in the regular expression correspond to fields in the dtype.
  kind: param
  key: 'param'
  arg_name: 'regexp'
  type_name: 'str or regexp'
  is_optional: False
- DocstringParam
  description: 'Dtype for the structured array; must be a structured datatype.'
  kind: param
  key: 'param'
  arg_name: 'dtype'
  type_name: 'dtype or list of dtypes'
  is_optional: False
- DocstringParam
  description: 'Encoding used to decode the inputfile. Does not apply to input streams.'
  kind: param
  key: 'param'
  arg_name: 'encoding'
  type_name: 'str'
  is_optional: True
  raw_type_name: 'str, optional'
- DocstringReturns
  description: |
    The output array, containing the part of the content of `file` that
    was matched by `regexp`. `output` is always a structured array.
  kind: returns
  key: 'returns'
  type_name: 'ndarray'
  is_generator: False
  return_name: 'output'
- DocstringRaises
  description: 'When `dtype` is not a valid dtype for a structured array.'
  kind: raises
  key: 'raises'
  type_name: 'TypeError'
- DocstringMeta
  description: 'fromstring, loadtxt'
  kind: text
  key: 'see_also'
  title: 'See Also'
- DocstringMeta
  description: |
    Dtypes for structured arrays can be specified in several forms, but all
    forms specify at least the data type and field name. For details see
    `basics.rec`.
  kind: text
  key: 'notes'
  title: 'Notes'
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: '>>> import numpy as np'
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: '>>> from io import StringIO'
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: '>>> text = StringIO("1312 foo\\n1534  bar\\n444   qux")'
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: '>>> regexp = r"(\\d+)\\s+(...)"  # match [digits, whitespace, anything]'
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: |
    >>> output = np.fromregex(text, regexp,
    ...                       [('num', np.int64), ('key', 'S3')])
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: |
    >>> output
    array([(1312, b'foo'), (1534, b'bar'), ( 444, b'qux')],
          dtype=[('num', '<i8'), ('key', 'S3')])
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: |
    >>> output['num']
    array([1312, 1534,  444])
=== detect
numpydoc
=== compose numpydoc
Construct an array from a text file, using regular expression parsing.

The returned array is always a structured array, and is constructed from
all matches of the regular expression in the file. Groups in the regular
expression are converted to fields of the structured array.

Parameters
----------
file : file, str, or pathlib.Path
    Filename or file object to read.

    .. versionchanged:: 1.22.0
        Now accepts `os.PathLike` implementations.
regexp : str or regexp
    Regular expression used to parse the file.
    Groups in the regular expression correspond to fields in the dtype.
dtype : dtype or list of dtypes
    Dtype for the structured array; must be a structured datatype.
encoding : str, optional
    Encoding used to decode the inputfile. Does not apply to input streams.

Returns
-------
output : ndarray
    The output array, containing the part of the content of `file` that
    was matched by `regexp`. `output` is always a structured array.

Raises
------
TypeError
    When `dtype` is not a valid dtype for a structured array.

See Also
--------
fromstring, loadtxt

Notes
-----
Dtypes for structured arrays can be specified in several forms, but all
forms specify at least the data type and field name. For details see
`basics.rec`.

Examples
--------
>>> import numpy as np
>>> from io import StringIO
>>> text = StringIO("1312 foo\n1534  bar\n444   qux")
>>> regexp = r"(\d+)\s+(...)"  # match [digits, whitespace, anything]
>>> output = np.fromregex(text, regexp,
...                       [('num', np.int64), ('key', 'S3')])
>>> output
array([(1312, b'foo'), (1534, b'bar'), ( 444, b'qux')],
      dtype=[('num', '<i8'), ('key', 'S3')])
>>> output['num']
array([1312, 1534,  444])
