Construct an array from a text file, using regular-expressions parsing.
Array is constructed from all matches of the regular expression in the file. Groups in the regular expression are converted to fields.
Parameters: | file : str or file
regexp : str or regexp
dtype : dtype or dtype list
|
---|
Examples
>>> f = open('test.dat', 'w')
>>> f.write("1312 foo\n1534 bar\n444 qux")
>>> f.close()
>>> np.fromregex('test.dat', r"(\d+)\s+(...)",
... [('num', np.int64), ('key', 'S3')])
array([(1312L, 'foo'), (1534L, 'bar'), (444L, 'qux')],
dtype=[('num', '<i8'), ('key', '|S3')])