Skip a specified number of columns with numpy.genfromtxt()

前端 未结 2 1885
没有蜡笔的小新
没有蜡笔的小新 2021-02-06 10:16

I have a large table (numbers in text format) that I would like to load with numpy.genfromtxt(). I would like to ignore the first n columns, say 5. I do no

2条回答
  •  别那么骄傲
    2021-02-06 10:48

    In newer versions of Numpy, np.genfromtxt can take an iterable argument, so you can wrap the file you're reading in a generator that generates lines, skipping the first N columns. If your numbers are space-separated, that's something like

    np.genfromtxt(" ".join(ln.split()[N:]) for ln in f)
    

提交回复
热议问题