numpy.frombuffer()

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.

  1. buffer: It represents an object that exposes a buffer interface.
  2. dtype: It represents the data type of the returned data type array. The default value is 0.
  3. count: It represents the length of the returned ndarray. The default value is -1.
  4. 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']
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +