Search code examples
pythonpython-2.7numpyreadfile

One-line piece of script to read a single row in a file as numpy.array


Simple question, I have a file with N entries and M values. I need a one-line piece of script to read the first or any single row of the file as numpy.array.


Solution

  • A=np.loadtxt('file_name',skiprows = N,max_rows =1)  #for rows
    B=np.loadtxt('file_name',usecols=M)              #for colomns