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

柔情痞子 提交于 2019-12-11 12:37:38

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/29720430/skip-a-specified-number-of-columns-with-numpy-genfromtxt-python-3-4-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!