如何在Google Colaboratory中导入和读取搁置文件或Numpy文件? [英] How to import and read a shelve or Numpy file in Google Colaboratory?

查看:395
本文介绍了如何在Google Colaboratory中导入和读取搁置文件或Numpy文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有file.npy,我想将其加载到 Google合作实验室笔记本中.我已经知道我必须从Google云端硬盘加载文件,但是我不知道该如何加载.

I have file.npy and I want to load it in Google Colaboratory Notebook. I already know that I must load the file from Google Drive, however I have no idea how to do so.

欢迎任何帮助

推荐答案

使用以下命令将文件上传到Colaboratory Notebook:

Upload your file into Colaboratory Notebook with the following:

from google.colab import files
uploaded = files.upload()

然后,您可以从uploaded对象访问文件的内容,然后将其写入文件:

Then you can reach the contents of your file from uploaded object and then write it into a file:

with open("my_data.h5", 'w') as f:
    f.write(uploaded[uploaded.keys()[0]])

如果您运行:

!ls

您将在当前目录中看到my_data.h5文件.

you will see my_data.h5 file in the current directory.

这是对我有用的方法.希望对您有所帮助.

This is the method that worked for me. Hope it helps.

这篇关于如何在Google Colaboratory中导入和读取搁置文件或Numpy文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆