NumPy ufuncLesson 39Free preview
ufunc Differences
This lesson is part of NumPy · All levels
Summary
Calculating the difference between successive elements in an array is very useful for analyzing changes or differences in time series data. You can repeat the difference many times with the n parameter and change the direction of the calculation through the axis parameter. The value is ultimately reduced by one element per differentiation level.
Key points
- Np.diff(array) produces a difference of consecutive elements (e[i+1] - e[i]).
- The n parameter repeats the differential operation n times.
- The axis parameters select the direction of differentiation on a multidimensional array.
- Each n-level reduces the number of resulting elements by one.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.