This function is used to create an array by using the specified buffer.
Syntax
snippet
numpy.frombuffer(buffer, dtype = float, count = -1, offset = 0)
Parameters
It accepts the following parameters.
- buffer: It represents an object that exposes a buffer interface.
- dtype: It represents the data type of the returned data type array. The default value is 0.
- count: It represents the length of the returned ndarray. The default value is -1.
- offset: It represents the starting position to read from. The default value is 0.
Return
The array version of the buffer is returned.
Example
snippet
import numpy as np
l = b'hello world'
print(type(l))
a = np.frombuffer(l, dtype = "S1")
print(a)
print(type(a))
Output:
Output
[b'h' b'e' b'l' b'l' b'o' b' ' b'w' b'o' b'r' b'l' b'd']