def diff(n=1,axis:-1)
      axis = check_axis(axis)
      if n < 0 || n >= shape[axis]
        raise ShapeError,"n=#{n} is invalid for shape[#{axis}]=#{shape[axis]}"
      end
      # calculate polynomial coefficient
      c = self.class[-1,1]
      2.upto(n) do |i|
        x = self.class.zeros(i+1)
        x[0..-2] = c
        y = self.class.zeros(i+1)
        y[1..-1] = c
        c = y - x
      end
      s = [true]*ndim
      s[axis] = n..-1
      result = self[*s].dup
      sum = result.inplace
      (n-1).downto(0) do |i|
        s = [true]*ndim
        s[axis] = i..-n-1+i
        sum + self[*s] * c[i] # inplace addition
      end
      return result
    end
def diff(n=1,axis:-1)
      axis = check_axis(axis)
      if n < 0 || n >= shape[axis]
        raise ShapeError,"n=#{n} is invalid for shape[#{axis}]=#{shape[axis]}"
      end
      # calculate polynomial coefficient
      c = self.class[-1,1]
      2.upto(n) do |i|
        x = self.class.zeros(i+1)
        x[0..-2] = c
        y = self.class.zeros(i+1)
        y[1..-1] = c
        c = y - x
      end
      s = [true]*ndim
      s[axis] = n..-1
      result = self[*s].dup
      sum = result.inplace
      (n-1).downto(0) do |i|
        s = [true]*ndim
        s[axis] = i..-n-1+i
        sum + self[*s] * c[i] # inplace addition
      end
      return result
    end
Calculate the n-th discrete difference along given axis.
 @example
   p x = Numo::DFloat[1, 2, 4, 7, 0]
   # Numo::DFloat#shape=[5]
   # [1, 2, 4, 7, 0]

   p x.diff
   # Numo::DFloat#shape=[4]
   # [1, 2, 3, -7]

   p x.diff(2)
   # Numo::DFloat#shape=[3]
   # [1, 1, -10]

   p x = Numo::DFloat[[1, 3, 6, 10], [0, 5, 6, 8]]
   # Numo::DFloat#shape=[2,4]
   # [[1, 3, 6, 10],
   #  [0, 5, 6, 8]]

   p x.diff
   # Numo::DFloat#shape=[2,3]
   # [[2, 3, 4],
   #  [5, 1, 2]]

   p x.diff(axis:0)
   # Numo::DFloat#shape=[1,4]
   # [[-1, 2, 0, -2]]