Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python,如何将矩阵添加到exist txt文件中_Python_Matrix_Save - Fatal编程技术网

python,如何将矩阵添加到exist txt文件中

python,如何将矩阵添加到exist txt文件中,python,matrix,save,Python,Matrix,Save,通过这种方式,我可以将矩阵X保存在txt中,并将#新切片添加到末尾 但是如果我想在X后面的文件底部添加Y呢 np.savetxt('workfile.txt',X,header='fist matrix',footer='\n') f = open('workfile.txt', 'a') f.write('# New slice\n') f.close() 这些句子不起作用,这表明 TypeError:必须是str,而不是bytes f = open('workfile.txt', 'a')

通过这种方式,我可以将矩阵X保存在txt中,并将#新切片添加到末尾 但是如果我想在X后面的文件底部添加Y呢

np.savetxt('workfile.txt',X,header='fist matrix',footer='\n')
f = open('workfile.txt', 'a')
f.write('# New slice\n')
f.close()
这些句子不起作用,这表明 TypeError:必须是str,而不是bytes

f = open('workfile.txt', 'a')
np.savetxt(f,Y,header='second matrix',footer='\n')