在阅读/存储文件时,我遇到了格式问题。任何评论/评论都欢迎如何解决这个问题。
我正在定义一些数组
filter
稍后将数据保存在文件中
pos_pb_now = np.array(pos_pb_now, dtype='f') # 6x3
pos_pw_now = np.array(pos_pw_now, dtype='f') #6x3
pos_ball_now = np.array(pos_ball_now, dtype='f') # 1x3
稍后恢复数据以供进一步使用;只有1个大小(n * 13)x 3的数组,下面这一行正在初始化它。
np.savetxt(f_store_handler, pos_pb_now, fmt='%5.2f', delimiter=' , ')
np.savetxt(f_store_handler, pos_pw_now, fmt='%5.2f', delimiter=' , ')
np.savetxt(f_store_handler, pos_ball_now, fmt='%5.2f', delimiter=' , ')
然后我修改了array_coord_sequence并希望一次性再次存储
array_coord_sequence = np.loadtxt(filename_coord_retrieve, delimiter=',', skiprows=0, dtype='f')
但出现错误
np.savetxt(f_store_handler_local, array_coord_sequence, fmt='%5.2f', delimiter=' , ')
更新1:代码示例如何修改array_coord_sequence(lfd_seq是一个整数)
Traceback (most recent call last):
store coord into file new/overwriting pos_uwr_player.csv
File "/home/family/glade/game_uwr/game_uwr.py", line 1844, in store_file_coord
np.savetxt(f_store_handler_local, array_coord_sequence, fmt='%5.2f', delimiter=' , ')
File "/usr/lib/python3/dist-packages/numpy/lib/npyio.py", line 1219, in savetxt
% (str(X.dtype), format))
TypeError: Mismatch between array dtype ('float32') and format specifier ('%5.2f , %5.2f , %5.2f')