【发布时间】:2020-02-13 08:16:10
【问题描述】:
类似于Meenakshi 我正在尝试使用 numpy 的 savetxt 函数将数据附加到文件中。
我有一个 .data 文件,我想将更多 float32 数据附加到。
responses = np.array(responses,np.float32)
responses = responses.reshape((responses.size,1))
# save as new training results
np.savetxt(sampleData,samples)
np.savetxt(responseData,responses)
# want the option to append to previously written results
我可以将以下内容附加为二进制文件,但我需要在 float32 中附加。
# append to old training results
with open(sampleData, 'ab+') as fs:
fs.write(samples)
with open(responseData, 'ab+') as fr:
fr.write(responses)
当我尝试时
# append to old training results
with open(sampleData, 'a+') as fs:
fs.write(samples)
with open(responseData, 'a+') as fr:
fr.write(responses)
我得到“TypeError:write() 参数必须是 str,而不是 numpy.ndarray”
鉴于上述情况,我应该使用什么语法/扩展名与 python 中的这种 .data 文件类型进行交互?
【问题讨论】:
-
到目前为止你尝试过什么?它说什么属性不存在?
-
我编辑了问题以使其更清楚:)
-
我更新了我的答案 - 看到了关于附加的部分,我之前错过了。
标签: python file types append file-extension