bundles / numpy 2.4.4 / numpy / rec / fromstring
function
numpy.rec:fromstring
source: /numpy/_core/records.py :752
Signature
def fromstring ( datastring , dtype = None , shape = None , offset = 0 , formats = None , names = None , titles = None , aligned = False , byteorder = None ) Summary
Create a record array from binary data
Extended Summary
Note that despite the name of this function it does not accept str instances.
Parameters
datastring: bytes-likeBuffer of binary data
dtype: data-type, optionalValid dtype for all arrays
shape: int or tuple of ints, optionalShape of each array.
offset: int, optionalPosition in the buffer to start reading from.
formats, names, titles, aligned, byteorderIf
dtypeisNone, these arguments are passed tonumpy.format_parserto construct a dtype. See that function for detailed documentation.
Returns
: np.recarrayRecord array view into the data in datastring. This will be readonly if
datastringis readonly.
Examples
a = b'\x01\x02\x03abc'
✓np.rec.fromstring(a, dtype='u1,u1,u1,S3')
✗grades_dtype = [('Name', (np.str_, 10)), ('Marks', np.float64), ('GradeLevel', np.int32)] grades_array = np.array([('Sam', 33.3, 3), ('Mike', 44.4, 5), ('Aadi', 66.6, 6)], dtype=grades_dtype)✓
np.rec.fromstring(grades_array.tobytes(), dtype=grades_dtype)
✗s = '\x01\x02\x03abc' np.rec.fromstring(s, dtype='u1,u1,u1,S3')✓
See also
Aliases
-
numpy.rec.fromstring