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,)
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,)