def unstructured_to_structured(data, dtype):
data = list(np.moveaxis(data, -1, 0))
leaves = len(rfn.flatten_descr(dtype))
if len(data) != leaves:
raise ValueError(
f"Incompatible shape, last dimension of data ({data.shape[-1]}) must match number of leaves in structured dtype ({leaves})."
)
new_data = _unstructured_to_structured_helper(data, dtype)
return new_data