python - Converting numpy Void array to record array? -


i have numpy array 8 16 byte long void records looks this:

array([[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0],        [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0],        [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0],        [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0],        [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0],        [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0],        [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0],        [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]],         dtype='|v16') 

and need cast array 8 16b long records of custom dtype looks this:

[(('x', 's0'), '<u4'), (('y', 's1'), '<u4'), (('z', 's2'), '<u4'), ('padding0', '<u4')] 

how can achieve that?

i've tried array.astype(self.dtype, copy=false, casting="unsafe"),

valueerror: setting array element sequence.

which doesn't make sense me.

this data comes pyopencl (memory mapping buffer), can't change input format or dtype.

as long number of bytes match, view can make kind of transformation. changes how data buffer 'viewed'.

in [36]: dt=np.dtype([(('x', 's0'), '<u4'), (('y', 's1'), '<u4'), (('z', 's2'), '<u4'), ('padding0', '<u4')]) in [37]: dt out[37]: dtype([(('x', 's0'), '<u4'), (('y', 's1'), '<u4'), (('z', 's2'), '<u4'), ('padding0', '<u4')])  in [39]: x = np.zeros((3,), dtype=dt) in [40]: x out[40]:  array([(0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)],       dtype=[(('x', 's0'), '<u4'), (('y', 's1'), '<u4'), (('z', 's2'), '<u4'), ('padding0', '<u4')]) in [41]: x.view('|v16') out[41]:  array([[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0],        [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0], [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]],       dtype='|v16') in [42]: x.view('|v16').view(dt) out[42]:  array([(0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)],       dtype=[(('x', 's0'), '<u4'), (('y', 's1'), '<u4'), (('z', 's2'), '<u4'), ('padding0', '<u4')]) 

i have experiment figure out whether astype or view right way transform structured array.


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -