I created this numpy array and stored it in disk as follows:
s = (b'foo', b'bar', b'baz', b'buzz')
def build_numpy_array():
return np.fromiter((s for _ in range(200)), dtype=[('foo','S40'),
('bar', 'S40'), ('baz', 'S40'),
('buzz', 'S40')
])
np.save('data.dat', {'data': build_numpy_array()})
This works fine
np.load('data.dat.npy')
But, I want to use it in memmap mode. So this fails
np.load('data.dat.npy',mmap_mode='r')
ValueError: Array can't be memory-mapped: Python objects in dtype.
And this gives weird encoding
np.memmap('data.dat.npy', mode='r',dtype=[('foo','S40'),
('bar', 'S40'), ('baz', 'S40'),
('buzz', 'S40')
])
(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00bar', b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00baz', b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00buz', b'z\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00foo')