numpy.ma.ediff1d() function in Python (original) (raw)
Last Updated : 12 Nov, 2020
numpy.ma.ediff1d() function return the differences between consecutive elements of an array.
Syntax : numpy.ma.ediff1d(arr, to_end = None, to_begin = None)
Parameters :
arr : [array_like] Input array.
to_end : [array_like, optional] Number to append at the end of the returned differences.
to_begin : [array_like, optional] Number to prepend at the beginning of the returned differences.Return : Return the differences between consecutive elements of an array.
Code #1:
Python3
import
numpy as geek
arr
=
geek.array([
3
,
5
,
8
,
4
,
12
])
gfg
=
geek.ma.ediff1d(arr)
print
(gfg)
Output:
[ 2 3 -4 8]
Code #2:
Python3
import
numpy as geek
arr
=
geek.array([
3
,
5
,
8
,
4
,
12
])
gfg
=
geek.ma.ediff1d(arr, to_begin
=
geek.array([
-
23
,
0
]), to_end
=
25
)
print
(gfg)
Output:
[-23 0 2 3 -4 8 25]
Similar Reads
- numpy.ma.fix_invalid() function | Python numpy.ma.fix_invalid() function return input with invalid data masked and replaced by a fill value. Where invalid data means values of nan, inf, etc. Syntax : numpy.ma.fix_invalid(arr, mask = False, copy = True, fill_value = None) Parameter : arr : [array_like] Input array. mask : [sequence, optiona 2 min read
- numpy.ma.filled() function - Python numpy.ma.filled() function return input as an array with masked data replaced by a fill value. If arr is not a MaskedArray, arr itself is returned. If arr is a MaskedArray and fill_value is None, fill_value is set to arr.fill_value. Syntax : numpy.ma.filled(arr, fill_value = None) Parameters : arr : 1 min read
- Numpy matrix.I function | Python With the help ofnumpy.matrix.I() function we can get the multiplicative inverse of the same size as of our given matrix. Syntax : numpy.matrix.I() Return : [matrix object] If self is non-singular, ret is such that ret * self == self * ret == np.matrix(np.eye(self[0, :].size) all return True. Return 1 min read
- numpy.i0() function | Python numpy.i0() function is the modified Bessel function of the first kind, order 0. it's usually denoted by I0. Syntax : numpy.i0(x) Parameters : x : [array_like, dtype float or complex] Argument of the Bessel function. Return : [ndarray, shape = x.shape, dtype = x.dtype] The modified Bessel function ev 1 min read
- Python | Numpy np.ediff1d() method With the help of np.ediff1d() method, we can get the 1D array of differences between two consecutive elements by using np.ediff1d() method. Syntax : np.ediff1d(array) Return : Return 1D array having differences of consecutive elements. Example #1 : In this example we can see that by using np.ediff1d 1 min read
- numpy.finfo() function – Python numpy.finfo() function shows machine limits for floating point types. Syntax : numpy.finfo(dtype) Parameters : dtype : [float, dtype, or instance] Kind of floating point data-type about which to get information. Return : Machine parameters for floating point types. Code #1 : # Python program explain 1 min read
- numpy.nanstd() function - Python numpy.nanstd() function compute the standard deviation along the specified axis, while ignoring NaNs. Syntax : numpy.nanstd(arr, axis = None, dtype = None, out = None, ddof = 0, keepdims) Parameters : arr : [array_like] Calculate the standard deviation of the non-NaN values. axis : [{int, tuple of i 2 min read
- Numpy ndarray.dot() function | Python The numpy.ndarray.dot() function computes the dot product of two arrays. It is widely used in linear algebra, machine learning and deep learning for operations like matrix multiplication and vector projections. Example: [GFGTABS] Python import numpy as np a = np.array([1, 2, 3]) b = np.array([4, 5, 2 min read
- numpy.ma.mask_cols() function | Python In thisnumpy.ma.mask_cols() function, mask columns of a 2D array that contain masked values. This function is a shortcut to mask_rowcols with axis equal to 1. Syntax : numpy.ma.mask_cols(arr, axis = None) Parameters : arr : [array_like, MaskedArray] The array to mask. axis : [int, optional] Axis alo 1 min read
- numpy.ma.notmasked_edges() function | Python numpy.ma.notmasked_edges() function find the indices of the first and last unmasked values along an axis. Return None, if all values are masked. Otherwise, return a list of two tuples, corresponding to the indices of the first and last unmasked values respectively. Syntax : numpy.ma.notmasked_edges( 2 min read