code: def _get_array(val, shape, default=None, dtype=np.float64):
      
      assert val is not None or default is not None
      if hasattr(val, '__len__') and len(val) == 0:  # pragma: no cover
          val = None
      # Do nothing if the array is already correct.
      if (isinstance(val, np.ndarray) and
              val.shape == shape and
              val.dtype == dtype):
          return val
      out = np.zeros(shape, dtype=dtype)
      # This solves `ValueError: could not broadcast input array from shape (n)
      # into shape (n, 1)`.
      if val is not None and isinstance(val, np.ndarray):
          if val.size == out.size:
              val = val.reshape(out.shape)
      out.flat[:] = val if val is not None else default
      assert out.shape == shape
      return out
docs: Ensure an object is an array with the specified shape.