code: def insert(arr, obj, values, axis=None):
      """
      Insert values along the given axis before the given indices.
  
      Parameters
      ----------
      arr : array like
          Input array.
      obj : int, slice or sequence of ints
          Object that defines the index or indices before which `values` is
          inserted.
      values : array_like
          Values to insert into `arr`. If the type of `values` is different
          from that of `arr`, `values` is converted to the type of `arr`.
          `values` should be shaped so that ``arr[...,obj,...] = values``
          is legal.
      axis : int, optional
          Axis along which to insert `values`.  If `axis` is None then `arr`
          is flattened first.
      Returns
      -------
      out : ndarray
          A copy of `arr` with `values` inserted.  Note that `insert`
          does not occur in-place: a new array is returned. If
          `axis` is None, `out` is a flattened array.
      See Also
      --------
      append : Append elements at the end of an array.
      concatenate : Join a sequence of arrays along an existing axis.
      delete : Delete elements from an array.
      Notes
      -----
      Note that for higher dimensional inserts `obj=0` behaves very different
      from `obj=[0]` just like `arr[:,0,:] = values` is different from
      `arr[:,[0],:] = values`.
      Examples
      --------
      >>> import mars.tensor as mt
      >>> a = mt.array([[1, 1], [2, 2], [3, 3]])
      >>> a.execute()
      array([[1, 1],
             [2, 2],
             [3, 3]])
      >>> mt.insert(a, 1, 5).execute()
      array([1, 5, 1, ..., 2, 3, 3])
      >>> mt.insert(a, 1, 5, axis=1).execute()
      array([[1, 5, 1],
             [2, 5, 2],
             [3, 5, 3]])
      Difference between sequence and scalars:
      >>> mt.insert(a, [1], [[1],[2],[3]], axis=1).execute()
      array([[1, 1, 1],
             [2, 2, 2],
             [3, 3, 3]])
      >>> b = a.flatten()
      >>> b.execute()
      array([1, 1, 2, 2, 3, 3])
      >>> mt.insert(b, [2, 2], [5, 6]).execute()
      array([1, 1, 5, ..., 2, 3, 3])
      >>> mt.insert(b, slice(2, 4), [5, 6]).execute()
      array([1, 1, 5, ..., 2, 3, 3])
      >>> mt.insert(b, [2, 2], [7.13, False]).execute() # type casting
      array([1, 1, 7, ..., 2, 3, 3])
      >>> x = mt.arange(8).reshape(2, 4)
      >>> idx = (1, 3)
      >>> mt.insert(x, idx, 999, axis=1).execute()
      array([[  0, 999,   1,   2, 999,   3],
             [  4, 999,   5,   6, 999,   7]])
      """
      arr = astensor(arr)
      if getattr(obj, "ndim", 0) > 1:  # pragma: no cover
          raise ValueError(
              "index array argument obj to insert must be one dimensional or scalar"
          )
  
      if axis is None:
          # if axis is None, array will be flatten
          arr_size = arr.size
          idx_length = calc_object_length(obj, size=arr_size)
          shape = (arr_size + idx_length,)
      else:
          validate_axis(arr.ndim, axis)
          idx_length = calc_object_length(obj, size=arr.shape[axis])
          shape = tuple(
              s + idx_length if i == axis else s
              for i, s in enumerate(arr.shape)
          )
  
      op = TensorInsert(
          index_obj=obj, values=values, axis=axis, dtype=arr.dtype
      )
      return op(arr, obj, values, shape)
  
imports: import numpy
  from ...None import opcodes
  from ...core import ENTITY_TYPE, recursive_tile
  from ...serialization.serializables import Int32Field, TupleField, AnyField, KeyField
  from ...utils import has_unknown_shape
  from ..datasource import tensor
  from ..operands import TensorHasInput, TensorOperandMixin
  from ..utils import filter_inputs, validate_axis, calc_object_length
label_desc: Use image node_id 1 for calling a global function with example usage: insert(arr, obj, values, axis) and returns: op