Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

method
python
numpy
communitycreator

What is the numpy.ma.frombuffer() function in Python?

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

The ma.frombuffer() function in Python is interprets a buffer as a one dimensional (1-D) array.

Syntax

ma.frombuffer(buffer, dtype=float, count=- 1, offset=0, *, like=None) = <numpy.ma.core._convert2ma object>
Syntax of the ma.frombuffer() function

Parameter value

The ma.frombuffer() function takes the following parameter values:

  • buffer: This represents an object which exposes the buffer interface. This is required.
  • dtype: This represents the data type of the output or the returned array. This is optional.
  • count: This represents the number of items to be read from the buffer. A value of -1 indicates all the items are present in the buffer. This is optional.
  • offset: This represents the offset from which we start reading the buffer. This is optional.
  • like: This represents a reference object to allow the creation of arrays that are not NumPy arrays.

Return value

The ma.frombuffer() function returns a 1-D array.

Example

import numpy as np
# creating a buffer
x = b'Hi how are you?'

# implementing the ma.frombuffer() function 
myarray=np.frombuffer(x, dtype='S1', count=10, offset=3)

print(myarray)
Implementing the "ma.frombuffer()" function

RELATED TAGS

method
python
numpy
communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring