简体   繁体   English

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

[英]How to use np.save to save files in different directory in python?

I want to save training in a different folder named Check . 我想将培训保存在名为Check的其他文件夹中。 How can I save this using np.save command? 如何使用np.save命令保存? I read about np.save command from documentation but it doesn't describe how to save it in different directory. 我从文档中读到了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)

From the ( DOCS ): 来自( DOCS ):

file : file, str, or pathlib.Path file:file,str或pathlib.Path

File or filename to which the data is saved. 保存数据的文件或文件名。 If file is a file-object, then the filename is unchanged. 如果file是文件对象,则文件名不变。 If file is a string or Path, a .npy extension will be appended to the file name if it does not already have one. 如果file是字符串或Path,则.npy扩展名将附加到文件名(如果它还没有)。

This states that if the filename has a directory (ie: Path), it will be stored there. 这表明如果文件名有一个目录(即:Path),它将被存储在那里。 So something like this should do what you need: 所以这样的事情应该做你需要的:

import os
np.save(os.path.join('Check', 'train_set'), training)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM