How to use np.save to save files in different directories in python?
I want to save training in a different folder named Check
. How do I save this with a command np.save
? I read about the command np.save
from the documentation but does not describe how to save it in a different directory.
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)
source to share
From ( DOCS ):
file: file, str or pathlib.Path
The file or filename in which the data is saved. If the file is a file object, then the file name is not changed. If the file is a string or Path, the .npy extension is appended to the file name if it does not already have one.
This means that if the filename has a directory (ie: path), it will be stored there. So, something like this should do what you want:
import os
np.save(os.path.join('Check', 'train_set'), training)
source to share