代码步骤:创建.txt文件→load需要打开的.npy文件→依次将.npy文件写入.txt文件
import numpy as np
# 创建一个txt文件,文件名为new
def text_create(name, msg):
desktop_path = "C:\\Users\\ASUS\\Desktop\\" # 新创建的txt文件的存放路径
full_path = desktop_path + name + '.txt' # 也可以创建一个.doc的word文档
file = open(full_path, 'w')
file.write(msg) #
file.close()
text_create('new', '')
#load需要打开的.npy文件
old_file = np.load('C:/Users/ASUS/Desktop/rrr.npy',encoding = "latin1",allow_pickle=True) #打开文件名为“rrr"的npy文件
print(old_file)
# 打开一个创建的new.txt存储文件,并依次写入
doc = open('new1.txt', 'a')
print(old_file, file=doc) #打印
如何创建.txt文件引用 https://blog.csdn.net/m0_71689546/article/details/126018991
如何将.npy中的内容写入.txt文件 https://blog.csdn.net/qq_43508270/article/details/126022055