writing .mat data to file in Google Drive using google colab

Viewed 176

I'm using google colab and I want to save an array in a .mat file, I used this code

import scipy.io
x = np.array([1,2,3,4,5,6,7,8,9])
mdic = {"x": x, "label": "array_data"}
scipy.io.savemat('x.mat', mdic)

here I could download this file on my computer, I want to know if there is any code that can save this file automatically to a folder in my google drive?

1 Answers

At first, you need to connect to your Google Drive:

from google.colab import drive
import os
drive.mount('/content/drive')

After this you can access contents of your Google Drive at `/content/drive/MyDrive':

! ls /content/drive/MyDrive
Related