前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >numpy.frombuffer()

numpy.frombuffer()

作者头像
狼啸风云
修改2022-09-03 21:10:23
1.5K0
修改2022-09-03 21:10:23
举报

numpy.frombuffer

numpy.frombuffer(bufferdtype=floatcount=-1offset=0)

Interpret a buffer as a 1-dimensional array.

Parameters:

buffer : buffer_like An object that exposes the buffer interface. dtype : data-type, optional Data-type of the returned array; default: float. count : int, optional Number of items to read. -1 means all data in the buffer. offset : int, optional Start reading the buffer from this offset (in bytes); default: 0.

Notes

If the buffer has data that is not in machine byte-order, this should be specified as part of the data-type, e.g.:

>>> dt = np.dtype(int)
>>> dt = dt.newbyteorder(‘>‘)
>>> np.frombuffer(buf, dtype=dt)

The data of the resulting array will not be byteswapped, but will be interpreted correctly.

Examples

>>> s = ‘hello world‘
>>> np.frombuffer(s, dtype=‘S1‘, count=5, offset=6)
array([‘w‘, ‘o‘, ‘r‘, ‘l‘, ‘d‘],
      dtype=‘|S1‘)
>>> np.frombuffer(b‘\x01\x02‘, dtype=np.uint8)
array([1, 2], dtype=uint8)
>>> np.frombuffer(b‘\x01\x02\x03\x04\x05‘, dtype=np.uint8, count=3)
array([1, 2, 3], dtype=uint8)

NumPy的ndarray数组对象不能像list一样动态地改变其大小,在做数据采集时很不方便。本文介绍如何通过np.frombuffer()实现动态数组。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-10-21 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • numpy.frombuffer
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档