Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- data = np.genfromtxt(fname, dtype = None,comments = '#', skip_header=1, usecols=(ucols))
- In [131]: arr=np.ones((3,), dtype='i,f,U10,i,f')
- In [132]: arr['f2']=['a','bc','def']
- In [133]: arr
- Out[133]:
- array([(1, 1., 'a', 1, 1.), (1, 1., 'bc', 1, 1.), (1, 1., 'def', 1, 1.)],
- dtype=[('f0', '<i4'), ('f1', '<f4'), ('f2', '<U10'), ('f3', '<i4'), ('f4', '<f4')])
- In [134]: np.savetxt('test',arr,fmt='%d,%e,%s,%d,%f')
- In [135]: cat test
- 1,1.000000e+00,a,1,1.000000
- 1,1.000000e+00,bc,1,1.000000
- 1,1.000000e+00,def,1,1.000000
- In [137]: np.genfromtxt('test',delimiter=',',dtype=None,encoding=None)
- Out[137]:
- array([(1, 1., 'a', 1, 1.), (1, 1., 'bc', 1, 1.), (1, 1., 'def', 1, 1.)],
- dtype=[('f0', '<i8'), ('f1', '<f8'), ('f2', '<U3'), ('f3', '<i8'), ('f4', '<f8')])
- In [138]: np.genfromtxt('test',delimiter=',',dtype=None,encoding=None,usecols=
- ...: (1,2,4))
- Out[138]:
- array([(1., 'a', 1.), (1., 'bc', 1.), (1., 'def', 1.)],
- dtype=[('f0', '<f8'), ('f1', '<U3'), ('f2', '<f8')])
Add Comment
Please, Sign In to add comment