Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

numpy

I want to save training in a different folder named Check. How can I save this using np.save command? I read about np.save command from documentation but it doesn't describe how to save it in 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)
like image 867
sara Avatar asked May 02 '17 06:05

sara


1 Answers

From the (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.

This states that if the filename has a directory (ie: Path), it will be stored there. So something like this should do what you need:

import os
np.save(os.path.join('Check', 'train_set'), training)
like image 96
Stephen Rauch Avatar answered Nov 05 '22 10:11

Stephen Rauch