我想将训练保存在名为 Check
的不同文件夹中。如何使用 np.save
命令保存它?我从文档中阅读了有关 np.save
命令的信息,但它没有描述如何将其保存在不同的目录中。
sample = np.arange(100).reshape(10,10)
split = 0.7
index = int(floor(len(sample)*split))
training = sample[:index]
np.save("Check"+'train_set.npy',training)
最佳答案
来自(DOCS):
file : file, str, or pathlib.Path
File or filename to which the data is saved. If file is a file-object, then the filename is unchanged. If file is a string or Path, a .npy extension will be appended to the file name if it does not already have one.
这说明如果文件名有一个目录(即:路径),它将存储在那里。所以像这样的事情应该做你需要的:
import os
np.save(os.path.join('Check', 'train_set'), training)
关于python - 如何使用 np.save 将文件保存在 python 的不同目录中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43731481/