Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

numpy loadtxt single line/row as list

I have a data file with only one line like:

 1.2  2.1  3.2

I used numpy version 1.3.0 loadtxt to load it

 a,b,c = loadtxt("data.dat", usecols(0,1,2), unpack=True)

The output was a float instead of array like

 a = 1.2

I expect it would be:

 a = array([1.2])

If i read a file with multiple lines, it's working.

like image 490
Thiru Avatar asked Nov 23 '12 11:11

Thiru


1 Answers

Simply use the numpy's inbuit loadtxt parameter ndmin.

a,b,c=np.loadtxt('data.dat',ndmin=2,unpack=True)

output

a=[1.2]
like image 144
Vinay B Avatar answered Sep 22 '22 20:09

Vinay B