[Numpy-discussion] A bug in loadtxt and how to convert a string array (hex data) to decimal?

frank wang f.yw@hotmail....
Thu Sep 18 16:27:49 CDT 2008

Hi, All,
I have found a bug in the loadtxt function. Here is the example. The file name is test.txt and contains:
"Thist is test"
3FF 3fE
3Ef 3e8
3Df 3d9
3cF 3c7
In the Python 2.5.2, I type:
test=loadtxt('test.txt',comments='"',dtype='string',converters={0:lambda s:int(s,16)})
test will contain
array([['102', '3fE'],
       ['100', '3e8'],
       ['991', '3d9'],
       ['975', '3c7']],
The first two values 102 and 100 are wrong. 
The reason I am doing this because that I have to process a large amount of data from a file. The data is in hex format. This is only way I found that I can efficiently convert the hex to decimal. 
Anyone has a good solution?
Get more out of the Web. Learn 10 hidden secrets of Windows Live.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20080918/09a18134/attachment.html 

More information about the Numpy-discussion mailing list