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

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

问题描述

我有 file.npy,我想将它加载到 Google Colaboratory 笔记本.我已经知道我必须从 Google Drive 加载文件,但是我不知道如何加载.

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天全站免登陆