Zero-Copy Data Processing in Python with memoryview

import numpy as np

# Create a mutable byte buffer
buf = bytearray(100)

# Create a memoryview
mv = memoryview(buf)

# Convert it to a NumPy array (zero-copy)
arr = np.frombuffer(mv, dtype=np.uint8)

print(arr.shape) # Output: (100,)

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top