Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Folder with Numpy Savetxt

Tags:

python

numpy

I'm trying loop over many arrays and create files stored in different folders.

Is there a way to have np.savetxt creating the folders I need as well?

Thanks

like image 923
Kostas Belivanis Avatar asked Oct 16 '25 03:10

Kostas Belivanis


2 Answers

savetxt just does a open(filename, 'w'). filename can include a directory as part of the path name, but you'll have to first create the directory with something like os.mkdir. In other words, use the standard Python directory and file functions.

like image 83
hpaulj Avatar answered Oct 18 '25 16:10

hpaulj


Actually in order to make all intermediate directories if needed the os.makedirs(path, exist_ok=True) . If not needed the command will not throw an error.

like image 28
Kostas Belivanis Avatar answered Oct 18 '25 16:10

Kostas Belivanis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!