code: def midpoint(xyz):
      """Midpoint of track
  
      Parameters
      ----------
      xyz : array-like shape (N,3)
         array representing x,y,z of N points in a track
  
      Returns
      -------
      mp : array shape (3,)
         Middle point of line, such that, if L is the line length then
         `np` is the point such that the length xyz[0] to `mp` and from
         `mp` to xyz[-1] is L/2.  If the middle point is not a point in
         `xyz`, then we take the interpolation between the two nearest
         `xyz` points.  If `xyz` is empty, return a ValueError
  
      Examples
      --------
      >>> from dipy.tracking.metrics import midpoint
      >>> midpoint([])
      Traceback (most recent call last):
         ...
      ValueError: xyz array cannot be empty
      >>> midpoint([[1, 2, 3]])
      array([1, 2, 3])
      >>> xyz = np.array([[1,1,1],[2,3,4]])
      >>> midpoint(xyz)
      array([ 1.5,  2. ,  2.5])
      >>> xyz = np.array([[0,0,0],[1,1,1],[2,2,2]])
      >>> midpoint(xyz)
      array([ 1.,  1.,  1.])
      >>> xyz = np.array([[0,0,0],[1,0,0],[3,0,0]])
      >>> midpoint(xyz)
      array([ 1.5,  0. ,  0. ])
      >>> xyz = np.array([[0,9,7],[1,9,7],[3,9,7]])
      >>> midpoint(xyz)
      array([ 1.5,  9. ,  7. ])
      """
      xyz = np.asarray(xyz)
      n_pts = xyz.shape[0]
      if n_pts == 0:
          raise ValueError("xyz array cannot be empty")
      if n_pts == 1:
          return xyz.copy().squeeze()
      cumlen = np.zeros(n_pts)
      cumlen[1:] = length(xyz, along=True)
      midlen = cumlen[-1] / 2.0
      ind = np.where((cumlen - midlen) > 0)[0][0]
      len0 = cumlen[ind - 1]
      len1 = cumlen[ind]
      Ds = midlen - len0
      Lambda = Ds / (len1 - len0)
      return Lambda * xyz[ind] + (1 - Lambda) * xyz[ind - 1]
  
imports: from dipy.utils.deprecator import deprecate_with_version
  from dipy.tracking.streamline import set_number_of_points
  import numpy
  from scipy.interpolate import splprep, splev
label_desc: Use image node_id 4 for calling a global function with example usage: midpoint(xyz) and returns: unknown, xyz