parameters: (file, regexp, dtype)
docstring: 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 : str or file
          File name or file object to read.
      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.
  
      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
      `doc.structured_arrays`.
  
      Examples
      --------
      >>> f = open('test.dat', 'w')
      >>> f.write("1312 foo\\n1534  bar\\n444   qux")
      >>> f.close()
  
      >>> regexp = r"(\\d+)\\s+(...)"  # match [digits, whitespace, anything]
      >>> output = np.fromregex('test.dat', regexp,
      ...                       [('num', np.int64), ('key', 'S3')])
      >>> output
      array([(1312L, 'foo'), (1534L, 'bar'), (444L, 'qux')],
            dtype=[('num', '<i8'), ('key', '|S3')])
      >>> output['num']
      array([1312, 1534,  444], dtype=int64)
docstring_summary: Construct an array from a text file, using regular expression parsing.
docstring_tokens: Construct an array from a text file using regular expression parsing .
function: def fromregex(file, regexp, dtype):
      """
      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 : str or file
          File name or file object to read.
      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.
  
      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
      `doc.structured_arrays`.
  
      Examples
      --------
      >>> f = open('test.dat', 'w')
      >>> f.write("1312 foo\\n1534  bar\\n444   qux")
      >>> f.close()
  
      >>> regexp = r"(\\d+)\\s+(...)"  # match [digits, whitespace, anything]
      >>> output = np.fromregex('test.dat', regexp,
      ...                       [('num', np.int64), ('key', 'S3')])
      >>> output
      array([(1312L, 'foo'), (1534L, 'bar'), (444L, 'qux')],
            dtype=[('num', '<i8'), ('key', '|S3')])
      >>> output['num']
      array([1312, 1534,  444], dtype=int64)
  
      """
      own_fh = False
      if not hasattr(file, "read"):
          file = open(file, 'rb')
          own_fh = True
  
      try:
          if not hasattr(regexp, 'match'):
              regexp = re.compile(asbytes(regexp))
          if not isinstance(dtype, np.dtype):
              dtype = np.dtype(dtype)
  
          seq = regexp.findall(file.read())
          if seq and not isinstance(seq[0], tuple):
              # Only one group is in the regexp.
              # Create the new array as a single data-type and then
              #   re-interpret as a single-field structured array.
              newdtype = np.dtype(dtype[dtype.names[0]])
              output = np.array(seq, dtype=newdtype)
              output.dtype = dtype
          else:
              output = np.array(seq, dtype=dtype)
  
          return output
      finally:
          if own_fh:
              file.close()
function_tokens: def fromregex ( file , regexp , dtype ) : own_fh = False if not hasattr ( file , "read" ) : file = open ( file , 'rb' ) own_fh = True try : if not hasattr ( regexp , 'match' ) : regexp = re . compile ( asbytes ( regexp ) ) if not isinstance ( dtype , np . dtype ) : dtype = np . dtype ( dtype ) seq = regexp . findall ( file . read ( ) ) if seq and not isinstance ( seq [ 0 ] , tuple ) : # Only one group is in the regexp. # Create the new array as a single data-type and then #   re-interpret as a single-field structured array. newdtype = np . dtype ( dtype [ dtype . names [ 0 ] ] ) output = np . array ( seq , dtype = newdtype ) output . dtype = dtype else : output = np . array ( seq , dtype = dtype ) return output finally : if own_fh : file . close ( )