numpy.frombuffer() function – Python (original) (raw)
Last Updated : 18 Aug, 2020
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
import
numpy as geek
gfg
=
geek.frombuffer(b
'\x01\x02\x03'
, dtype
=
geek.uint8)
print
(gfg)
Output :
[1 2 3]
Code #2 :
Python3
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]
Similar Reads
- numpy.fromiter() function – Python NumPy's fromiter() function is a handy tool for creating a NumPy array from an iterable object. This iterable can be any Python object that provides elements one at a time. The function is especially useful when you need to convert data from a custom data source, like a file or generator, into a Num 2 min read
- numpy.fromstring() function – Python numpy.fromstring() function create a new one-dimensional array initialized from text data in a string. Syntax : numpy.fromstring(string, dtype = float, count = -1, sep = ' ') Parameters : string : [str] A string that contained the data. dtype : [data-type, optional] Data-type of the array. Default d 1 min read
- numpy.fromfunction() function – Python numpy.fromfunction() function construct an array by executing a function over each coordinate and the resulting array, therefore, has a value fn(x, y, z) at coordinate (x, y, z). Syntax : numpy.fromfunction(function, shape, dtype) Parameters : function : [callable] The function is called with N para 2 min read
- numpy.byte_bounds() function – Python numpy.byte_bounds() function returns pointers to the end-points of an array. Syntax : numpy.byte_bounds(arr) Parameters : arr : [ndarray] Input array. Return : [tuple of 2 integers] The first integer is the first byte of the array, the second integer is just past the last byte of the array. If arr i 1 min read
- numpy.who function - Python numpy.who() function print the NumPy arrays in the given dictionary. Syntax : numpy.who(vardict = None) Parameters : vardict : [dict, optional] A dictionary possibly containing ndarrays. Return : Returns ‘None’. If there is no dictionary passed in or vardict is None then returns NumPy arrays in the 1 min read
- Python 3 - input() function In Python, we use the input() function to take input from the user. Whatever you enter as input, the input function converts it into a string. If you enter an integer value still input() function converts it into a string. Python input() Function SyntaxSyntax: input(prompt) Parameter: Prompt: (optio 3 min read
- Python PIL | Image.frombuffer() method PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The Image module provides a class with the same name which is used to represent a PIL image. The module also provides a number of factory functions, including functions to load images from files, 2 min read
- bytearray() function - Python The bytearray() function in Python creates a mutable sequence of bytes, which is essentially an array of integers in the range 0 to 255 (representing byte values). Unlike the immutable bytes type, bytearray allows us to modify its contents after creation, making it useful for tasks like binary data 5 min read
- Python open() Function The Python open() function is used to open internally stored files. It returns the contents of the file as Python objects. Python open() Function SyntaxThe open() function in Python has the following syntax: Syntax: open(file_name, mode)Â Parameters: file_name: This parameter as the name suggests, i 3 min read
- numpy.sctype2char() function – Python numpy.sctype2char() function return the string representation of a scalar dtype. Syntax : numpy.sctype2char(sctype) Parameters : sctype : [scalar dtype or object] If a sctype is a scalar dtype, the corresponding string character is returned. If an object, sctype2char tries to infer its scalar type a 1 min read