我可以在一台机器上以字节数组的形式读取h5文件,将该字节流传输到另一台计算机,然后从另一台机器上的字节数组加载吗? [英] Can I read h5 file on one machine as bytearray, stream that bytearray to other machine and then load it from bytearray on other machine?

查看:71
本文介绍了我可以在一台机器上以字节数组的形式读取h5文件,将该字节流传输到另一台计算机,然后从另一台机器上的字节数组加载吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下要求:我在一台(源)计算机上有h5文件,我想在另一台(目标)计算机上使用.目前,我觉得我应该在源计算机上将h5文件读取为字节数组,将字节流传输到目标计算机,然后从目标计算机上的字节数组加载h5文件.

I have following requirement: I have h5 file on one (source) machine, which I want to use in other (target) machine. Currently I feel I should read that h5 file as bytearray on source machine, stream the bytearray to target machine and then load h5 file from bytearray on target machine.

问题1.这种方法可以吗?还是有其他方法,可能更好?

Q1. Is this approach ok? Or there is any other approach, possibly better?

答案中,我发现我们可以从字节数组中加载h5文件.但是,如何从文件系统上的给定h5文件中获得这种有效的字节数组.我尝试使用通常的open("temp.h5")获取字节数组,但无法正常工作.

In this answer, I find that we can load h5 file from bytearray. But how can I get such valid bytearray from given h5 file on filesystem. I tried getting bytearray with usual open("temp.h5"), but it was not working.

旧的nabble线程似乎在讨论相同的问题.有人做过吗? 第二季度.谁能告诉我如何完成此任务?甚至可行吗?

Also this old nabble thread seems to discuss the same. Has anyone done this before? Q2. Can anyone tell how can I get this done? Or even if its doable?

推荐答案

这种方法可以吗?还是有其他方法,可能更好?

Is this approach ok? Or there is any other approach, possibly better?

您的方法对我来说听起来很合理.

Your approach sounds reasonable to me.

但是如何从文件系统上的给定h5文件中获得这样的有效字节数组.我尝试使用通常的open("temp.h5")获取字节数组,但无法正常工作.

But how can I get such valid bytearray from given h5 file on filesystem. I tried getting bytearray with usual open("temp.h5"), but it was not working.

您应该使用'b'模式将文件读取为二进制文件:

You should read the file as a binary file using the 'b' mode:

with open('some_file.txt', 'rb') as f:
    print(f.read())

>>> b'hello world'

谁能告诉我该怎么做?甚至可行吗?

Can anyone tell how can I get this done? Or even if its doable?

这是完全可行的.只需使用'rb'模式读取您的HDF5文件,通过套接字发送数据,然后使用我的上一个答案.

It is totally doable. Just read your HDF5 file with 'rb' mode, send the data through a socket, and read the file at the other side using the method in my previous answer.

这篇关于我可以在一台机器上以字节数组的形式读取h5文件,将该字节流传输到另一台计算机,然后从另一台机器上的字节数组加载吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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