It looks like both recfromtxt and loadtxt are flexible enough to
handle string/bytes en/decoding, - with a bit of work and using enough
information

>>> dtype=[('f0', '<i4'), ('f1', '<i4'), ('f2', '<i4'), ('f3', '<U9')]

>>> data = numpy.recfromtxt(open('Õscar_3.txt',"rb"), dtype=dtype, 
>>> delimiter=',',converters={3:lambda x: x.decode('utf8')})
>>> data['f3'] == 'Õscar'
array([False, False, False,  True], dtype=bool)
>>> data
rec.array([(1, 2, 3, 'hello'), (5, 6, 7, 'Õscarscar'), (15, 2, 3, 'hello'),
       (20, 2, 3, 'Õscar')],
      dtype=[('f0', '<i4'), ('f1', '<i4'), ('f2', '<i4'), ('f3', '<U9')])


>>> data = numpy.loadtxt(open('Õscar_3.txt',"rb"), dtype=dtype, 
>>> delimiter=',',converters={3:lambda x: x.decode('utf8')})
>>> data
array([(1, 2, 3, 'hello'), (5, 6, 7, 'Õscarscar'), (15, 2, 3, 'hello'),
       (20, 2, 3, 'Õscar')],
      dtype=[('f0', '<i4'), ('f1', '<i4'), ('f2', '<i4'), ('f3', '<U9')])
>>>

Josef
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to