MCPcopy Index your code
hub / github.com/numpy/numpy / ediff1d

Function ediff1d

numpy/ma/extras.py:1229–1264  ·  view source on GitHub ↗

Compute the differences between consecutive elements of an array. This function is the equivalent of `numpy.ediff1d` that takes masked values into account, see `numpy.ediff1d` for details. See Also -------- numpy.ediff1d : Equivalent function for ndarrays. Examples

(arr, to_end=None, to_begin=None)

Source from the content-addressed store, hash-verified

1227#####--------------------------------------------------------------------------
1228
1229def ediff1d(arr, to_end=None, to_begin=None):
1230 """
1231 Compute the differences between consecutive elements of an array.
1232
1233 This function is the equivalent of `numpy.ediff1d` that takes masked
1234 values into account, see `numpy.ediff1d` for details.
1235
1236 See Also
1237 --------
1238 numpy.ediff1d : Equivalent function for ndarrays.
1239
1240 Examples
1241 --------
1242 >>> import numpy as np
1243 >>> arr = np.ma.array([1, 2, 4, 7, 0])
1244 >>> np.ma.ediff1d(arr)
1245 masked_array(data=[ 1, 2, 3, -7],
1246 mask=False,
1247 fill_value=999999)
1248
1249 """
1250 arr = ma.asanyarray(arr).flat
1251 ed = arr[1:] - arr[:-1]
1252 arrays = [ed]
1253 #
1254 if to_begin is not None:
1255 arrays.insert(0, to_begin)
1256 if to_end is not None:
1257 arrays.append(to_end)
1258 #
1259 if len(arrays) != 1:
1260 # We'll save ourselves a copy of a potentially large array in the common
1261 # case where neither to_begin or to_end was given.
1262 ed = hstack(arrays)
1263 #
1264 return ed
1265
1266
1267def unique(ar1, return_index=False, return_inverse=False):

Callers 5

test_ediff1dMethod · 0.90
test_ediff1d_tobeginMethod · 0.90
test_ediff1d_toendMethod · 0.90
test_ediff1d_ndarrayMethod · 0.90

Calls 1

hstackFunction · 0.85

Tested by 5

test_ediff1dMethod · 0.72
test_ediff1d_tobeginMethod · 0.72
test_ediff1d_toendMethod · 0.72
test_ediff1d_ndarrayMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…