numpy 1.22.4 Pypi GitHub Homepage
Other Docs
NotesParametersRaisesReturnsBackRef
fromregex(file, regexp, dtype, encoding=None)

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.

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 :None:None:`basics.rec`.

Parameters

file : path or file

Filename or file object to read.

versionchanged

Now accepts :None:None:`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.

versionadded

Raises

TypeError

When dtype is not a valid dtype for a structured array.

Returns

output : ndarray

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

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

See Also

fromstring
loadtxt

Examples

>>> 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])
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

numpy.loadtxt

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /numpy/lib/npyio.py#1465
type: <class 'function'>
Commit: