gpt4 book ai didi

python - 如何使用 np.save 将文件保存在 python 的不同目录中?

转载 作者:太空狗 更新时间:2023-10-30 00:53:47 25 4
gpt4 key购买 nike

我想将训练保存在名为 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com