Open In App

numpy.frombuffer() function – Python

Last Updated : 18 Aug, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report

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 :

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)

Output :

[1 2 3]

Code #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)

Output :

[1 2 3 4 5]


Article Tags :
Practice Tags :

Similar Reads

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy