[SciPy-User] How to specify the dtype in IO

Jose Gomez-Dans jgomezdans@gmail....
Thu Apr 22 04:51:44 CDT 2010


Hi,

On 21 April 2010 19:32, Leon Sit <wing1127aishi@gmail.com> wrote:

> I have a csv file with columns of the following dtype
> int8, int8, int8, float, float, ............
> and the column size is arbitrary. Is there a way to specific the dtype
> in genfromtxt() such that it knows the first three column is int and
> float otherwise?
>

Can't you use numpy.loadtxt for this? From the help

 >>> d = StringIO("M 21 72\nF 35 58")

 >>> np.loadtxt(d, dtype={'names': ('gender', 'age', 'weight'),
 ...                      'formats': ('S1', 'i4', 'f4')})
 array([('M', 21, 72.0), ('F', 35, 58.0)],
          dtype=[('gender', '|S1'), ('age', '<i4'), ('weight', '<f4')])


Jose
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20100422/43923e00/attachment.html 


More information about the SciPy-User mailing list