I am using R/Python diff() operation. e.g., https://docs.scipy.org/doc/numpy-1.14.0/reference/generated/numpy.diff.html

I would like to know if there is a mathematical function that denotes what diff does?

In other words, assume I have a list of N numbers. How can I denote this using a methematical function?

mylist = [x1, x2, x2, ..., xN]

I am happy to provide more details if needed.


Assume you want to apply diff to a vector $(x_1, \dots, x_n)$ of length $n$. The result will be the vector $(d_1, \dots, d_{n-1})$ of length $n-1$ with entries

$$ d_i = x_{i+1}-x_i. $$

Some people will use the notation $x_{[i]}$ or similar to indicate the vector $x$ with the $i$th component left out, i.e., $x_{[i]}=(x_1, \dots, x_{i-1}, x_{i+1}, \dots, x_n)$. With this, you can write more concisely in vector form

$$ d = x_{[1]} - x_{[n]}.$$

  • $\begingroup$ Thanks a lot for the great answer. Just wondering how to write this function sd(diff(x))/abs(mean(diff(x))) mathematically. Currently, I am having it as σ(diff(x))/|µ(diff(x))|. Please let me know your thoughts on this. I look forward to hearing from you. Thank you very much :) $\endgroup$ – Emi Apr 21 at 8:32
  • 1
    $\begingroup$ That sounds useful enough. You can always write down the formulas for the mean and SD in terms of the differences $d_i$. And if you really want, you can substitute in the $x_i$, but it will get progressively less enlightening. $\endgroup$ – Stephan Kolassa Apr 21 at 8:40
  • $\begingroup$ Interesting notation for leaving out $i$; haven't seen that one before. I have often seen $x_{-i}$ for that $\endgroup$ – duckmayr Apr 21 at 11:43
  • $\begingroup$ @StephanKolassa I did not get what you said. It would be really great if you could show me what you said symbolically. I look forward to hearing from you. Thank you once again :) $\endgroup$ – Emi Apr 21 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.