Slide 17
Slide 17 text
Docstrings now and then
D e f i n i t i o n : np. d i f f (a, n=1, a x i s =-1)
Docstring :
C a l c u l a t e the n- th o r d e r d i s c r e t e d i f f e r e n c e along given a x i s .
The f i r s t o r d e r d i f f e r e n c e i s given by ‘‘ out [n] = a[n+1] - a[n]‘‘ along
the given axis , h i g h e r o r d e r d i f f e r e n c e s are c a l c u l a t e d by using ‘ d i f f ‘
r e c u r s i v e l y .
Parameters
----------
a : a r r a y l i k e
Input a r r a y
n : int , o p t i o n a l
The number of times v a l u e s are d i f f e r e n c e d .
a x i s : int , o p t i o n a l
The a x i s along which the d i f f e r e n c e i s taken , d e f a u l t i s the l a s t
a x i s .
Returns
-------
d i f f : ndarray
The ‘n‘ o r d e r d i f f e r e n c e s . The shape of the output i s the same as ‘a‘
except along ‘ axis ‘ where the dimension i s s m a l l e r by ‘n‘.
See Also
--------
gradient , e d i f f 1 d , cumsum
Examples
--------
>>> x = np. a r r a y ([1, 2, 4, 7, 0])
>>> np. d i f f (x)
a r r a y ([ 1, 2, 3, -7])
>>> np. d i f f (x , n=2)
a r r a y ([ 1, 1, -10])
much better now!
Parameters and their type
Suggestion of other functions
Simple example