【问题标题】:how to convert a .dat file into an array in python如何在python中将.dat文件转换为数组
【发布时间】:2018-11-11 09:52:13
【问题描述】:

我在计算 .dat 文件中数字的平均值时遇到问题。 我的想法是将 .dat 转换为数组,然后用numpy 计算平均值。这里出现了问题。 .dat 文件具有以下结构:

#x #y
221.0 434.0
63.5 76.0
78.0 411.5
345.0 58.5

第一列是 x 坐标,第二列是 y 坐标。我想要 x 和 y 坐标的平均值,但逻辑上没有第一行。

谁能帮帮我?

【问题讨论】:

    标签: arrays python-2.7 numpy


    【解决方案1】:

    好吧,我不得不承认这并不像我想象的那么困难。使用 numpy.loadtxt() 函数,可以使用参数 skiprows=1 轻松跳过第一行。

    https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.loadtxt.html

    【讨论】:

      猜你喜欢
      • 2018-03-24
      • 2013-10-05
      • 1970-01-01
      • 2012-07-15
      • 1970-01-01
      • 1970-01-01
      • 2016-08-19
      • 2013-07-01
      • 2022-01-22
      相关资源
      最近更新 更多