numpy loadtxt single line/row as list

前端 未结 3 1624

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(\         


        
3条回答
  •  佛祖请我去吃肉
    2021-01-12 13:25

    The simple way without using reshape is, to explicitly typecast the list

     a,b,c = loadtxt("data.dat", usecols(0,1,2), unpack=True)
     a,b,c = (a,b,c) if usi.shape else ([a], [b], [c])
    

    This works faster than the reshape!

提交回复
热议问题