Numpy cho phép bạn làm điều này rất nhanh. Trong trường hợp này, tôi nghĩ rằng cách dễ nhất là sử dụng trực tiếp hàm tạo
import numpy as np
firingBlocks = 10**4
lasers = 32
packet_raw = np.random.bytes[42 + firingBlocks*100]
%timeit readDataPacket[memoryview[packet_raw]]
# 1 loop, best of 3: 807 ms per loop
%timeit with_numpy[packet_raw]
# 100 loops, best of 3: 10.8 ms per loop
5:import numpy as np
def with_numpy[buffer]:
# Construct ndarray with: shape, dtype, buffer, offset, strides.
rotational = np.ndarray[[firingBlocks,], '