I have four numpy arrays that has about N=5 million rows each.
The shape of them are:
- a: (N, 3, dtype=float32)
- b: (N, 4, dtype=float32)
- c: (N, 3, dtype=uint8)
- d: (N, 4, dtype=uint8)
I want to pack them into a binary file with the same ordering.
This is what I have currently.
buffer = BytesIO()
for row in zip(a, b, c, d):
buffer.write(row[0].tobytes())
buffer.write(row[1].tobytes())
buffer.write(row[2].tobytes())
buffer.write(row[3].tobytes())
with open(output_path, "wb") as f:
f.write(buffer.getvalue())
Is there a more efficient method instead of looping it N times like what I had?