Search code examples
pythonpython-3.xgenfromtxt

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


import os
import numpy as np
import matplotlib.pyplot as plt

# Open a file
path = "input/"

filelist = list(filter(lambda s: s.endswith(".asc"), os.listdir(path)))
firstImage = np.genfromtxt (" ".join(ln.split()[1:]) for ln in path+next(iter(filelist)))

what is wrong? getting: TypeError: Can't convert 'bytes' object to str implicitly


Solution

  • Check out the function's doc, it seems able to to all kinds of crazy things out of the box :

    http://docs.scipy.org/doc/numpy/reference/generated/numpy.genfromtxt.html

    Including but not limited to, using the usecols parameters would allow you to skip using some columns.

    Then there would be no need for fancy operations