Reputation: 95
How can I create a numpy array from a python list of bytes objects of an arbitrary (but known) size?
Example:
size = 10
byte_list = [np.random.default_rng().bytes(size) for i in range(100)]
numpy_array = # make array from byte_list
# do something with the array
test_vals = np.random.default_rng().choice(numpy_array, size=10)
I tried to do something like this, but got an error that it didn't understand 'B10' as a data type.
numpy_array = np.fromiter(byte_list, dtype=np.dtype(f'B{size}'), count=100)
Upvotes: 0
Views: 58