I have a multidimensional numpy array arr1
which I would like to save to a binary file in the .npy
format.
import numpy as np
import os
current_dir_path = "/Users/.../desktop"
os.chdir(current_dir_path) # changed to "desktop" subdirectory
filename = "my_array.npy" # create name for numpy array file
np.save(filename, arr1) # save the numpy array arr1 with filename my_array.npy
I have multiple subdirectories where I would like to save this file, e.g. "public", "desktop", "downloads", etc.
Question 1: How do I save this file into multiple subdirectories with this script? I don't think using os.chdir()
makes sense.
Question 2: How do I do this such that if there is one "error" (e.g. I set up the path incorrectly for one subdirectory, it continues rather than throwing an error and not working with the other subdirectories?)