Subdivide int16 into 2 int8‘s, called x and y. 0 and 1 are the offsets in bytes:
np.dtype((np.int16, {'x':(np.int8,0), 'y':(np.int8,1)}))
dtype(('
或者根据你的情况改编:In [30]: x=np.arange(12,dtype=np.int32)*1000
In [39]: dt=np.dtype((np.int32, {'f0':(np.uint8,0),'f1':(np.uint8,1),'f2':(np.uint8,2), 'f3':(np.uint8,3)}))
In [40]: x1=x.view(dtype=dt)
In [41]: x1['f0']
Out[41]: array([ 0, 232, 208, 184, 160, 136, 112, 88, 64, 40, 16, 248], dtype=uint8)
In [42]: x1['f1']
Out[42]: array([ 0, 3, 7, 11, 15, 19, 23, 27, 31, 35, 39, 42], dtype=uint8)
比较In [38]: x%256
Out[38]: array([ 0, 232, 208, 184, 160, 136, 112, 88, 64, 40, 16, 248])2) Tuple argument: The only relevant tuple case that applies to record structures is when a structure is mapped to an existing data type.