Reputation: 59
Im trying to save a numpy file in a specific directory and overwrite it. How can i do this?
path = os.path.join(data_path, created_folder, 'testone')
with open('{}.npy'.format('testone'), 'ab') as f:
np.save(f, mydata)
Upvotes: 0
Views: 1261
Reputation: 1482
Your code opens the file for appending and you didn't give it the correct path you defined. To overwrite it, use the mode w
like this:
path = os.path.join(data_path, created_folder, 'testone')
with open('{}.npy'.format(path), 'wb') as f:
np.save(f, mydata)
Upvotes: 1