I am trying to store fixed width binary data in a numpy array. However, if my data has trailing zeros, they are lost. They work if I use the void type, but I want to save them as strings of bytes. Is there any way to do this?
>>> import numpy as np
>>> varr = np.array([(b'abc\x00\x00',), (b'de\x00\x00\x00',)], dtype='V5')
[[[97 98 99 0 0]]
[[100 101 0 0 0]]]
>>> sarr = np.array([(b'abc\x00\x00',), (b'de\x00\x00\x00',)], dtype='S5')
[[b'abc']
[b'de']]
source
share