[Numpy-discussion] Help using numPy to create a very large multi dimensional array

Christian K. ckkart at hoc.net
Wed Apr 18 02:09:57 EDT 2007


Bruno Santos wrote:
> I try to use the expression as you said, but I'm not getting the desired 
> result,
> My text file look like this:
> 
> # num rows=115 num columns=2634
> AbassiM.txt 0.033023 0.033023 0.033023 0.165115 0.462321....0.000000
> AgricoleW.txt 0.038691 0.038691 0.038691 0.232147 0.541676....0.215300
> AliR.txt 0.041885 0.041885 0.041885 0.125656 0.586395....0.633580
> .....
> ....
> ....
> ZhangJ.txt 0.047189 0.047189 0.047189 0.155048 0.613452....0.000000

I guess N.fromfile can't handle non numeric data. Use something like 
this instead (not tested):

import numpy as N

data = open('name of file').readlines()

data = N.array([[float(x) for x in row.split(' ')[1:]] for row in data[1:]])

(the above expression should be one line)

Christian




More information about the NumPy-Discussion mailing list