numpy.frombuffer() in Python
numpy.frombuffer() in Python The frombuffer() function of Python numpy class creates an array by using the given buffer. Syntax
numpy.frombuffer(buffer, dtype=float, count=-1, offset=0)Parameter The numpy.frombuffer() method consists of four parameters, which are as follows:
- buffer: This parameter represents an object that depicts a buffer interface.
- dtype: It represents the data type of the returned data type array. It is an optional parameter, and by default,its value is 0.
- count: It represents the length of the returned ndarray. It is an optional parameter, and its default value is -1.
- offset: It represents the starting position to read from. It is also an optional parameter, and its default value is 0.
# Python Programming giving an example for # numpy.frombuffer() function importnumpy as numpy obj = b'This is my numpy program' print(type(obj)) n = numpy.frombuffer(obj, dtype = "S1") print(n) print(type(n))Output
<class 'bytes'> [b'T' b'h' b'i' b's' b' ' b'i' b's' b' ' b'm' b'y' b' ' b'n' b'u' b'm' b'p' b'y' b' ' b'p' b'r' b'o' b'g' b'r' b'a' b'm'] <class 'numpy.ndarray'>