[Numpy-discussion] behaviour of np.loadtxt

Davide davide.lasagna@polito...
Wed Sep 14 07:24:17 CDT 2011


Dear list,

I'm encountering a problem with np.loadtxt.

Suppose i have a file containing three columns of data (and 10 rows), like:

0.001 0.003 0.005
0.001 0.003 0.006
0.002 0.004 0.002
0.004 0.002 0.007
0.001 0.003 0.006
0.002 0.004 0.002
0.004 0.002 0.007
0.001 0.003 0.006
0.002 0.004 0.002
0.004 0.002 0.007

If i give:

  len ( np.loadtxt( filename, unpack=True ) )

i get 3, since i have a three rows array. That's fine.

If instead the file has a single column, i.e.,

0.004
0.002
0.007
0.004
0.002
0.007
0.004
0.002
0.007
0.004

the command

  len ( np.loadtxt( filename, unpack=True ) )

returns 10, where i would expect it to return 1, to be consistent with 
the behaviour when there are multiple columns.

Is there a reason for why it is not like that?


Cheers

Davide Lasagna






More information about the NumPy-Discussion mailing list