首页 > 解决方案 > numpy savetext 格式的帮助会产生错误

问题描述

我必须将相机距离导出到 txt/数据文件。当我在工作时遇到错误。

任何想法如何克服它。

未发布完整代码

perimeter = cv2.arcLength(cnt,True)

g = float("{0:.2f}".format(perimeter))

timestamped_camera_readings = np.append(timestamped_sensor_readings, (((154*58)/(g/4))*0.2645 ))

with open("camera_diatance.txt", "ab") as f:
    np.savetxt(f, np.expand_dims(timestamped_camera_readings, axis=0),  fmt=write_fmt)

将其保存到文件

Error raised:
Traceback (most recent call last):
File "/home/pi/merger/merger.py", line 118, in <module>
np.savetxt(f, np.expand_dims(timestamped_camera_readings, 
axis=0),fmt=write_fmt)
File "/usr/lib/python3/dist-packages/numpy/lib/npyio.py", line 1196, in 

savetxt 引发错误 ValueError:fmt 的 % 格式数量错误:%4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %.0f

标签: pythonnumpy

解决方案


推荐阅读