使用numpy.genfromtxt()python 3.4错误跳过指定数量的列 [英] Skip a specified number of columns with numpy.genfromtxt() python 3.4 error

查看:178
本文介绍了使用numpy.genfromtxt()python 3.4错误跳过指定数量的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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)))

怎么了?得到:TypeError:无法将字节"对象隐式转换为str

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

推荐答案

查看该函数的文档,似乎能够开箱即用地进行各种疯狂的事情:

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

包括但不限于使用usecols参数将允许您跳过使用某些列的操作.

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

这篇关于使用numpy.genfromtxt()python 3.4错误跳过指定数量的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆