code: def sparse_diff(array, n=1, axis=-1):
      
      if (n < 0) or (int(n) != n):
          raise ValueError('Expected order is non-negative integer, '\
                           'but found: {}'.format(n))
      if not sp.sparse.issparse(array):
          warnings.warn('Array is not sparse. Consider using numpy.diff')
  
      if n == 0:
          return array
  
      nd = array.ndim
      slice1 = [slice(None)]*nd
      slice2 = [slice(None)]*nd
      slice1[axis] = slice(1, None)
      slice2[axis] = slice(None, -1)
      slice1 = tuple(slice1)
      slice2 = tuple(slice2)
  
      A = sparse_diff(array, n-1, axis=axis)
      return A[slice1] - A[slice2]
docs: A ported sparse version of np.diff.
      Uses recursion to compute higher order differences
  
      Parameters
      ----------
      array : sparse array
      n : int, default: 1
          differencing order
      axis : int, default: -1
          axis along which differences are computed
  
      Returns
      -------
      diff_array : sparse array
                   same shape as input array,
                   but 'axis' dimension is smaller by 'n'.