def realign_dtype(dtype, offsets):
 (cls, args, state) = dtype.__reduce__()
 (names, fields) = state[3:5]
 fields = fields.copy()
 max_offset = 0
 itemsize = state[5]
 if ((fields is None) or (len(offsets) != len(names))):
  raise ValueError('Dtype must be a structured dtype, and length of offsets list must be the same as the number of fields.')
 for (name, offset) in zip(names, offsets):
  field = fields[name]
  if (offset == field[1]):
   continue
  fields[name] = (field[0], offset)
  if (offset > max_offset):
   itemsize = (offset + field[0].itemsize)
   max_offset = offset
 new_typespec = '|V{0}'.format(itemsize)
 new_state = ((state[:4] + (fields, itemsize)) + state[6:])
 new_dtype = cls(new_typespec, *args[1:])
 new_dtype.__setstate__(new_state)
 return new_dtype

def realign_dtype ( dtype , offsets ) : ( cls , args , state ) = dtype . __reduce__ ( ) ( names , fields ) = state [ 3 : 5 ] fields = fields . copy ( ) max_offset = 0 itemsize = state [ 5 ] if ( ( fields is None ) or ( len ( offsets ) != len ( names ) ) ) : raise ValueError ( 'Dtype must be a structured dtype, and length of offsets list must be the same as the number of fields.' ) for ( name , offset ) in zip ( names , offsets ) : field = fields [ name ] if ( offset == field [ 1 ] ) : continue fields [ name ] = ( field [ 0 ] , offset ) if ( offset > max_offset ) : itemsize = ( offset + field [ 0 ] . itemsize ) max_offset = offset new_typespec = '|V{0}' . format ( itemsize ) new_state = ( ( state [ : 4 ] + ( fields , itemsize ) ) + state [ 6 : ] ) new_dtype = cls ( new_typespec , * args [ 1 : ] ) new_dtype . __setstate__ ( new_state ) return new_dtype
given a numpy struct dtype object an a list of integer offsets .