将txt文件加载到numpy数组中 [英] Load txt file into numpy array
本文介绍了将txt文件加载到numpy数组中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将txt文件加载到numpy数组中.该文件具有以下格式:
I want to load a txt file into a numpy array. The file has this format:
1,10,1,11,1,13,1,12,1,1,9
2,11,2,13,2,10,2,12,2,1,9
3,12,3,11,3,13,3,10,3,1,9
4,10,4,11,4,1,4,13,4,12,9
4,1,4,13,4,12,4,11,4,10,9
1,2,1,4,1,5,1,3,1,6,8
1,9,1,12,1,10,1,11,1,13,8
2,1,2,2,2,3,2,4,2,5,8
3,5,3,6,3,9,3,7,3,8,8
4,1,4,4,4,2,4,3,4,5,8
.
.
.
宽度为11个值,高度为25010(所以我不想手动将它们放入数组中)
a width of 11 values and a height of 25010 (so I don't want to put them manually into the array)
我已经尝试过 load
, loadtxt
, loadfile
和 genfromtxt
.他们都失败了.我很确定逗号是问题所在.
I already tried load
, loadtxt
, loadfile
and genfromtxt
. All of them failed.
I'm pretty sure the commas are the problem.
您有解决方案吗?
推荐答案
您需要将定界符指定为<code>,:
You need to specify the delimiter as ,
:
import numpy as np
data = np.loadtxt("file.txt", delimiter=",")
这篇关于将txt文件加载到numpy数组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文