栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

将二进制字符串转换为numpy数组

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

将二进制字符串转换为numpy数组

>>> np.frombuffer(b'x00x00x80?x00x00x00@x00x00@@x00x00x80@', dtype='<f4') # or dtype=np.dtype('<f4'), or np.float32 on a little-endian system (which most computers are these days)array([ 1.,  2.,  3.,  4.], dtype=float32)

或者,如果您想要大端字节序:

>>> np.frombuffer(b'x00x00x80?x00x00x00@x00x00@@x00x00x80@', dtype='>f4') # or dtype=np.dtype('>f4'), or np.float32  on a big-endian systemarray([  4.60060299e-41,   8.96831017e-44,   2.30485571e-41,         4.60074312e-41], dtype=float32)

b
到Python 3不是现有必要的,当然。

实际上,如果您实际上是使用二进制文件从中加载数据,则甚至可以跳过using-a-
string步骤,并使用直接从文件中加载数据

numpy.fromfile()

另外,以防万一,请输入dtype参考:http
:
//docs.scipy.org/doc/numpy/reference/arrays.dtypes.html



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/624306.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号