code: def detrend(data, axis=-1, type="linear", bp=0):
      """
      Remove linear trend along axis from data.
  
      Parameters
      ----------
      data : array_like
          The input data.
      axis : int, optional
          The axis along which to detrend the data. By default this is the
          last axis (-1).
      type : {'linear', 'constant'}, optional
          The type of detrending. If ``type == 'linear'`` (default),
          the result of a linear least-squares fit to `data` is subtracted
          from `data`.
          If ``type == 'constant'``, only the mean of `data` is subtracted.
      bp : array_like of ints, optional
          A sequence of break points. If given, an individual linear fit is
          performed for each part of `data` between two break points.
          Break points are specified as indices into `data`.
  
      Returns
      -------
      ret : ndarray
          The detrended input data.
  
      Examples
      --------
      >>> from scipy import signal
      >>> randgen = np.random.RandomState(9)
      >>> npoints = 1000
      >>> noise = randgen.randn(npoints)
      >>> x = 3 + 2*np.linspace(0, 1, npoints) + noise
      >>> (signal.detrend(x) - noise).max() < 0.01
      True
  
      """
      if type not in ["linear", "l", "constant", "c"]:
          raise ValueError("Trend type must be 'linear' or 'constant'.")
      data = asarray(data)
      dtype = data.dtype.char
      if dtype not in "dfDF":
          dtype = "d"
      if type in ["constant", "c"]:
          ret = data - expand_dims(mean(data, axis), axis)
          return ret
      else:
          dshape = data.shape
          N = dshape[axis]
          bp = sort(unique(r_[0, bp, N]))
          if np.any(bp > N):
              raise ValueError(
                  "Breakpoints must be less than length "
                  "of data along given axis."
              )
          Nreg = len(bp) - 1
          # Restructure data so that axis is along first dimension and
          #  all other dimensions are collapsed into second dimension
          rnk = len(dshape)
          if axis < 0:
              axis = axis + rnk
          newdims = r_[axis, 0:axis, axis + 1 : rnk]
          newdata = reshape(
              transpose(data, tuple(newdims)), (N, _prod(dshape) // N)
          )
          newdata = newdata.copy()  # make sure we have a copy
          if newdata.dtype.char not in "dfDF":
              newdata = newdata.astype(dtype)
          # Find leastsq fit and remove it for each piece
          for m in range(Nreg):
              Npts = bp[m + 1] - bp[m]
              A = ones((Npts, 2), dtype)
              A[:, 0] = cast[dtype](arange(1, Npts + 1) * 1.0 / Npts)
              sl = slice(bp[m], bp[m + 1])
              coef, resids, rank, s = linalg.lstsq(A, newdata[sl])
              newdata[sl] = newdata[sl] - dot(A, coef)
          # Put data back in original shape.
          tdshape = take(dshape, newdims, 0)
          ret = reshape(newdata, tuple(tdshape))
          vals = list(range(1, rnk))
          olddims = vals[:axis] + [0] + vals[axis:]
          ret = transpose(ret, tuple(olddims))
          return ret
  
imports: from __future__ import division, print_function, absolute_import
  import operator
  import threading
  import sys
  import timeit
  from scipy.spatial import cKDTree
  from .None import sigtools, dlti
  from ._upfirdn import upfirdn, _output_len
  from scipy._lib.six import callable
  from scipy._lib._version import NumpyVersion
  from scipy import fftpack, linalg
  from scipy.fftpack.helper import _init_nd_shape_and_axes_sorted
  from numpy import allclose, angle, arange, argsort, array, asarray, atleast_1d, atleast_2d, cast, dot, exp, expand_dims, iscomplexobj, mean, ndarray, newaxis, ones, pi, poly, polyadd, polyder, polydiv, polymul, polysub, polyval, product, r_, ravel, real_if_close, reshape, roots, sort, take, transpose, unique, where, zeros, zeros_like
  import numpy
  import math
  from scipy.special import factorial
  from .windows import get_window
  from ._arraytools import axis_slice, axis_reverse, odd_ext, even_ext, const_ext
  from .filter_design import cheby1, _validate_sos
  from .fir_filter_design import firwin
label_desc: Use image node_id 35 for calling a global function with example usage: detrend(data, axis, type, bp) and returns: ret, ret