numpy.frombuffer()函數將緩衝區解釋為一維數組。
用法:numpy.frombuffer(buffer, dtype = float, count = -1, offset = 0)
參數:
buffer:[buffer_like]公開緩衝區接口的對象。
dtype:[數據類型,可選]返回的數組的數據類型,默認數據類型為float。
count:[int,可選]要讀取的項目數。
offset:[int,可選]從此偏移量開始讀取緩衝區,默認值為0。
Return:此函數將緩衝區解釋為一維數組。
代碼1:
Python3
# Python program explaining
# numpy.frombuffer() function
# importing numpy as geek
import numpy as geek
gfg = geek.frombuffer(b'\x01\x02\x03', dtype = geek.uint8)
print (gfg)
輸出:
[1 2 3]
代碼2:
Python3
# Python program explaining
# numpy.frombuffer() function
# importing numpy as geek
import numpy as geek
gfg = geek.frombuffer(b'\x01\x02\x03\x04\x05\x06\x07', dtype = geek.uint8, count = 5)
print (gfg)
輸出:
[1 2 3 4 5]
相關用法
- Python numpy.ma.where()用法及代碼示例
- Python numpy.ix_()用法及代碼示例
- Python numpy.cov()用法及代碼示例
- Python Numpy recarray.ptp()用法及代碼示例
- Python numpy.issctype()用法及代碼示例
- Python Numpy MaskedArray.all()用法及代碼示例
- Python Numpy recarray.put()用法及代碼示例
- Python Numpy recarray.dot()用法及代碼示例
- Python Numpy recarray.min()用法及代碼示例
- Python Numpy recarray.max()用法及代碼示例
- Python Numpy recarray.mean()用法及代碼示例
- Python numpy.find_common_type()用法及代碼示例
- Python numpy.promote_types()用法及代碼示例
- Python Numpy MaskedArray.any()用法及代碼示例
- Python numpy.typename()用法及代碼示例
- Python numpy.intersect1d()用法及代碼示例
- Python numpy.in1d()用法及代碼示例
- Python numpy.union1d()用法及代碼示例
注:本文由純淨天空篩選整理自sanjoy_62大神的英文原創作品 numpy.frombuffer() function – Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。