【问题标题】:storing sensor readings through numpy to a data file ( python 2.7 )通过 numpy 将传感器读数存储到数据文件(python 2.7)
【发布时间】:2019-06-05 12:57:30
【问题描述】:

我正在从传感器获取 3 轴的加速度读数并尝试通过 numpy 将其导出到数据文件。

function 'lsm6ds33.get_accelerometer_g_forces()' 返回一个浮点列表,如 [0.5455445 , 0.2565622 0.0545412]

我得到 n 个空数据文件, 我可以使用日志功能来制作它吗?

问候。

accelArray= lsm6ds33.get_accelerometer_g_forces() #用于保存数组的临时变量

DataOut = column_stack(accelArray) 没有帮助。

from altimu10v5.lsm6ds33 import LSM6DS33
from time import sleep
import numpy as np

lsm6ds33 = LSM6DS33()
lsm6ds33.enable()

while True:


    DataOut = column_stack(lsm6ds33.get_accelerometer_g_forces())
    savetxt('output.dat', DataOut, fmt=( '%2.2f', '%2.2f', '%2.2f'))
    sleep(1)

【问题讨论】:

  • 您在某处缩进了代码,但您不应该这样做。这就是错误的意思。

标签: python numpy


【解决方案1】:

savetxt 输入扩展为二维数组对我有用。试试:

x = [0.5455445, 0.2565622, 0.0545412]
np.savetxt('output.dat',np.reshape(x, (1,3)),  fmt='%2.2f %2.2f %2.2f')  

或:

x = [0.5455445, 0.2565622, 0.0545412]
np.savetxt('output.dat',np.expand_dims(x, axis=0),  fmt='%2.2f %2.2f %2.2f')  

【讨论】:

  • 嘿。问题得到了回答,无论如何现在我只有一组读数,我需要在更多次/周期内完成传感器读数。这怎么可能实现。
  • 不确定你的意思。例子?
  • 该函数返回几个数组,例如 [0.2555 , 0.152455 , 0.545455] [0.5454, 0.1455 , 0.5455] [0.2555 , 0.152455 , 0.545455] 现在我只将第一行导出到数据文件。如何保存所有条目。
  • 请创建另一个线程,显示您尝试过的示例代码以及运行时遇到的错误。
猜你喜欢
  • 2019-10-22
  • 2021-03-01
  • 2019-04-04
  • 1970-01-01
  • 2013-02-03
  • 1970-01-01
  • 2013-09-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多