bundles / numpy 2.4.3 / numpy / ma / core / frombuffer
function
numpy.ma.core:frombuffer
source: /numpy/ma/core.py :8749
Signature
def frombuffer ( buffer , dtype = <class 'float'> , count = -1 , offset = 0 , * , like = None ) Summary
Interpret a buffer as a 1-dimensional array.
Parameters
buffer: buffer_likeAn object that exposes the buffer interface.
dtype: data-type, optionalData-type of the returned array. Default is numpy.float64.
count: int, optionalNumber of items to read.
-1means all data in the buffer.offset: int, optionalStart reading the buffer from this offset (in bytes); default: 0.
like: array_like, optionalReference object to allow the creation of arrays which are not NumPy arrays. If an array-like passed in as
likesupports the__array_function__protocol, the result will be defined by it. In this case, it ensures the creation of an array object compatible with that passed in via this argument.
Returns
: out: MaskedArray
Notes
If the buffer has data that is not in machine byte-order, this should be specified as part of the data-type, e.g.
>>> dt = np.dtype(int) >>> dt = dt.newbyteorder('>') >>> np.frombuffer(buf, dtype=dt) # doctest: +SKIP
The data of the resulting array will not be byteswapped, but will be interpreted correctly.
This function creates a view into the original object. This should be safe in general, but it may make sense to copy the result when the original object is mutable or untrusted.
Examples
import numpy as np s = b'hello world' np.frombuffer(s, dtype='S1', count=5, offset=6)
np.frombuffer(b'\x01\x02', dtype=np.uint8) np.frombuffer(b'\x01\x02\x03\x04\x05', dtype=np.uint8, count=3)
See also
- ndarray.tobytes
Inverse of this operation, construct Python bytes from the raw data bytes in the array.
Aliases
-
numpy.ma.frombuffer