, , , , , . dtype .
TypeError: cannot perform accumulate with flexible type, delimiter. , LineSplitter. , ( "" ).
genfromtxt docs:
: str, int , , . . .
genfromtxt , .split, loadtxt, , re.
{TypeError}a bytes-like object is required, not 'str', dtype 'str'. , record unicode ( Py3). , BytesIO(record.encode()).
genfromtxt :
record = b'....'
np.genfromtxt([record], ....)
records = b"""one line
tow line
three line
"""
np.genfromtxt(records.splitlines(), ....)
genfromtxt , 32 :
In [19]: A=np.genfromtxt([record],dtype=None,delimiter='|')
In [20]: len(A.dtype)
Out[20]: 32
In [21]: A
Out[21]:
array((b'0002 00038 1', False, 3.6412123, 1.08701186, 14.1, -23.0, 69, 82, 1.8, 1.9, 1968.56, 1957.3, 3, 1.0, 3.0, 0.9, 3.0, 12.444, 0.213, 11.907, 0.189, 999, False, False, 3.64117944, 1.08706861, 1.83, 1.73, 81.0, 104.7, False, 0.0),
dtype=[('f0', 'S12'), ('f1', '?'), ('f2', '<f8'), ('f3', '<f8'), ('f4', '<f8'), ... ('f26', '<f8'), ('f27', '<f8'), ('f28', '<f8'), ('f29', '<f8'), ('f30', '?'), ('f31', '<f8')])
np.array([x for x in re.split(b'\|| ',record)],dtype=dform)
. , dform , .
, , .
np.array([(record1...), (record2...), ....], dtype([(field1),(field2 ),...]))
. , dform, 66 v 17. , dform 66 , .
dtype, , .
In [41]: np.zeros((1,),dform)
Out[41]:
array([ ((0, 0, 0), '', (0.0, 0.0), (0.0, 0.0), (0, 0, 0.0, 0.0), (0.0, 0.0), 0, (0.0, 0.0, 0.0, 0.0), ((0.0, 0.0), (0.0, 0.0)), 0, '', '', (0.0, 0.0), (0.0, 0.0), (0.0, 0.0), '', 0.0)],
dtype=[('starid', [('TYC1', '<i4'), ('TYC2', '<i4'), ('TYC3', '<i4')]), ('pflag', '<U'), ('starBearing', [('rightAscension', '<f8'), ('declination', '<f8')]), ('properMotion', [('rightAscension', '<f8'), ('declination', '<f8')]), ('uncertainty', [('rightAscension', '<i4'), ('declination', '<i4'), ('pmRA', '<f8'), ('pmDc', '<f8')]), ('meanEpoch', ....('solutionType', '<U'), ('correlation', '<f8')])
In [64]: for name in A.dtype.names:
print(A[name].dtype)
....:
[('TYC1', '<i4'), ('TYC2', '<i4'), ('TYC3', '<i4')]
<U1
[('rightAscension', '<f8'), ('declination', '<f8')]
[('rightAscension', '<f8'), ('declination', '<f8')]
[('rightAscension', '<i4'), ('declination', '<i4'), ('pmRA', '<f8'), ('pmDc', '<f8')]
[('rightAscension', '<f8'), ('declination', '<f8')]
int32
[('rightAscension', '<f8'), ('declination', '<f8'), ('pmRA', '<f8'), ('pmDc', '<f8')]
[('BT', [('mag', '<f8'), ('err', '<f8')]), ('VT', [('mag', '<f8'), ('err', '<f8')])]
int32
<U1
<U1
[('rightAscension', '<f8'), ('declination', '<f8')]
[('rightAscension', '<f8'), ('declination', '<f8')]
[('rightAscension', '<f8'), ('declination', '<f8')]
<U1
float64
34 dtype. "", 2-4 , .
2 - |, record.split(b'|') 34 .
genfromtxt:
In [79]: np.genfromtxt([record],delimiter='|',dtype=dform)
Out[79]:
array(((2, 38, 1), '', (3.6412123, 1.08701186), (14.1, -23.0),
(69, 82, 1.8, 1.9), (1968.56, 1957.3), 3, (1.0, 3.0, 0.9, 3.0),
((12.444, 0.213), (11.907, 0.189)), 999, '', '',
(3.64117944, 1.08706861), (1.83, 1.73), (81.0, 104.7), '', 0.0),
dtype=[('starid', [('TYC1', '<i4'), ('TYC2', '<i4'), ('TYC3', '<i4')]),
('pflag', '<U'),
('starBearing', [('rightAscension', '<f8'), ('declination', '<f8')]),
('properMotion', [('rightAscension', '<f8'), ('declination', '<f8')]),
('uncertainty', [('rightAscension', '<i4'), ('declination', '<i4'), ('pmRA', '<f8'), ('pmDc', '<f8')]),
('meanEpoch', [('rightAscension', '<f8'), ('declination', '<f8')]),
('numPos', '<i4'),
('fitGoodness', [('rightAscension', '<f8'), ('declination', '<f8'), ('pmRA', '<f8'), ('pmDc', '<f8')]),
('magnitude', [('BT', [('mag', '<f8'), ('err', '<f8')]), ('VT', [('mag', '<f8'), ('err', '<f8')])]),
('starProximity', '<i4'), ('tycho1flag', '<U'), ('hipparcosNumber', '<U'),
('observedPos', [('rightAscension', '<f8'), ('declination', '<f8')]),
('observedEpoch', [('rightAscension', '<f8'), ('declination', '<f8')]),
('observedError', [('rightAscension', '<f8'), ('declination', '<f8')]), ('solutionType', '<U'), ('correlation', '<f8')])
. genfromtxt . , np.array().
, /, genfromtxt .