code: def _unflatten(flat, model):
      """Restores an arbitrary nested structure to a flattened iterable.
  
      See also :func:`_flatten`.
  
      Args:
          flat (array): 1D array of items
          model (array, Iterable, Number): model nested structure
  
      Raises:
          TypeError: if ``model`` contains an object of unsupported type
  
      Returns:
          Union[array, list, Any], array: first elements of flat arranged into the nested
          structure of model, unused elements of flat
      """
      if isinstance(model, (numbers.Number, str)):
          return flat[0], flat[1:]
  
      if isinstance(model, np.ndarray):
          idx = model.size
          res = np.array(flat)[:idx].reshape(model.shape)
          return res, flat[idx:]
  
      if isinstance(model, Iterable):
          res = []
          for x in model:
              val, flat = _unflatten(flat, x)
              res.append(val)
          return res, flat
  
      raise TypeError(f"Unsupported type in the model: {type(model)}")
  
file_path: pennylane/pennylane/utils.py
imports: from collections.abc import Iterable
  import functools
  import inspect
  import numbers
  import numpy
  import pennylane
label_desc: Use image node_id 2 for calling a global function with example usage: _unflatten(flat, model) and returns: flat,  flat, res,  flat, res,  flat