numpy.frombuffer() function – Python
Last Updated :
18 Aug, 2020
Improve
numpy.frombuffer() function interpret a buffer as a 1-dimensional array.
Syntax : numpy.frombuffer(buffer, dtype = float, count = -1, offset = 0)
Parameters :
buffer : [buffer_like] An object that exposes the buffer interface.
dtype : [data-type, optional] Data-type of the returned array, default data-type is float.
count : [int, optional] Number of items to read.
offset : [int, optional] Start reading the buffer from this offset, default is 0.
Return : This function interpret a buffer as a 1-dimensional array.
Code #1 :
# 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)
Output :
[1 2 3]
Code #2 :
# 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)
Output :
[1 2 3 4 5]