0

I fromfile using a structured dtype and have one field that is raw hexbytes ('V2) - it looks like this:

[[b'\x00\x00', b'\x05\x01', b'\x00\x00', b'\x00\x00', b'\x00\x00' .....],
...
[b'\x00\x00', b'\x05\x01', b'\x00\x00', b'\x00\x00', b'\x00\x00' .....]] - the sub-array is shape (44640, 50)

I'd like to decode this entire array into string literals and keep the same shape (e.g. each 2byte chunk from b'\x05\x01' into '0501')

Tried iterating through using bytes.hex() instance method but doesn't keep the 2bytes x 50 structure ..

Always extremely grateful for your time and advice...


copied from comment with guess as to line breaks

dt3 = np.dtype([('DIG', 'u1', (digField)), ('ANL', 'V2', (anField)), ('MSG', 'u1', (260 - digField - (anField * 2))), ('DAT', 'u1', (20))])
raw_ry = np.fromfile(logpath, dtype=dt3, count=-1)
dt4 = np.dtype('U')
anDecode_ry = np.array([item.hex() for item in raw_ry['ANL']], dtype=dt4)
hpaulj
  • 221,503
  • 14
  • 230
  • 353
  • `[s.hex() for s in [b'\x00\x00', b'\x05\x01', b'\x00\x00', b'\x00\x00', b'\x00\x00']]` – hpaulj Aug 29 '20 at 02:26
  • I don't think you'll get much more help without an actual array example. Clearly a list of strings taken from your array display is not enough to convey the important details. – hpaulj Aug 30 '20 at 15:40

0 Answers0