As mentioned in a comment from @hpaulj, you can accomplish this using the stride_tricks module. You need both np.frombuffer and np.lib.stride_tricks.as_strided :
Collect data from a NumPy array
In [1]: import numpy as np In [2]: x = np.random.random((3, 4)).astype(dtype='f4') In [3]: buffer = x.data In [4]: dtype = x.dtype In [5]: shape = x.shape In [6]: strides = x.strides
Recover NumPy Array
In [7]: xx = np.frombuffer(buffer, dtype) In [8]: xx = np.lib.stride_tricks.as_strided(xx, shape, strides)
Check Results
In [9]: x Out[9]: array([[ 0.75343359, 0.20676662, 0.83675659, 0.99904215], [ 0.37182721, 0.83846378, 0.6888299 , 0.57195812], [ 0.39905572, 0.7258808 , 0.88316005, 0.2187883 ]], dtype=float32) In [10]: xx Out[10]: array([[ 0.75343359, 0.20676662, 0.83675659, 0.99904215], [ 0.37182721, 0.83846378, 0.6888299 , 0.57195812], [ 0.39905572, 0.7258808 , 0.88316005, 0.2187883 ]], dtype=float32) In [11]: x.strides Out[11]: (16, 4) In [12]: xx.strides Out[12]: (16, 4)
source share