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

标签 python numpy

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

相关文章:

python - 参数 #2 'mat1' 的张量在 CPU 上,但预计它在 GPU 上

python - PyQt:如何在子类 QWidget 中接收键盘事件?

Python 将 base64 字符串绘制为图像

python - 每次按每列分组计算

python - django 测试 RequestFactory 无法使路由参数工作

javascript - Python 将 JavascriptSerializer 转换为日期时间?

python - 曲率的数值计算

python - 将 Pandas 列中的整数值转换为字符串

python - 在 python 中编码和渲染(网络)图

python - 删除 numba.lowering.LoweringError : Internal error