Mayama
Mayama

Reputation: 59

How to overwrite npy file and save it in a directory?

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

Answers (1)

TC Arlen
TC Arlen

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

Related Questions