我想导入一个.dat文件,其中包括
lines/header/numbers/lines
Run Code Online (Sandbox Code Playgroud)
像这个例子
start using data to calculate something
x y z g h
1 4 6 8 3
4 5 6 8 9
2 3 6 8 5
end the data that I should import.
Run Code Online (Sandbox Code Playgroud)
现在我正在尝试读取此文件,删除第一行和最后一行并将数字放入数组中并对其进行一些基本计算,但我无法摆脱这些行。我曾经data = np.genfromtxt('sample.dat')导入数据,但是有了线,我什么也做不了。谁能帮我?
也许这对你有帮助:
import numpy as np
data = np.genfromtxt('sample.dat',
skip_header=1,
skip_footer=1,
names=True,
dtype=None,
delimiter=' ')
print(data)
# Output: [(1, 4, 6, 8, 3) (4, 5, 6, 8, 9) (2, 3, 6, 8, 5)]
Run Code Online (Sandbox Code Playgroud)
有关所用参数的更多信息,请参阅 numpy 文档:https : //numpy.org/doc/stable/reference/generated/numpy.genfromtxt.html
| 归档时间: |
|
| 查看次数: |
32637 次 |
| 最近记录: |