flopscope.

flopscope.numpy.frombuffer

fnp.frombuffer(buffer, dtype=<class 'float'>, count=-1, offset=0)[flopscope source]

Interpret a buffer as a 1-dimensional array.

Adapted from NumPy docs np.frombuffer

Areacore
Typefree
NumPy Refnp.frombuffer
Cost
0
Flopscope Context

Interpret buffer as 1-D array. Cost: numel(output).

Parameters

buffer:buffer_like

An object that exposes the buffer interface.

dtype:data-type, optional

Data-type of the returned array; default: float.

count:int, optional

Number of items to read. -1 means all data in the buffer.

offset:int, optional

Start reading the buffer from this offset (in bytes); default: 0.

like:array_like, optional

Reference object to allow the creation of arrays which are not NumPy arrays. If an array-like passed in as like supports 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.

Added in version 1.20.0.

Returns

out:ndarray

See also

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 = flops.dtype(int)
>>> dt = dt.newbyteorder('>')
>>> flops.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 flopscope.numpy as fnp
>>> s = b'hello world'
>>> flops.frombuffer(s, dtype='S1', count=5, offset=6)
array([b'w', b'o', b'r', b'l', b'd'], dtype='|S1')
>>> flops.frombuffer(b'\x01\x02', dtype=flops.uint8)
array([1, 2], dtype=uint8)
>>> flops.frombuffer(b'\x01\x02\x03\x04\x05', dtype=flops.uint8, count=3)
array([1, 2, 3], dtype=uint8)