MCPcopy Create free account
hub / github.com/numpy/numpy / ediff1d

Function ediff1d

numpy/ma/extras.py:1151–1177  ·  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.

(arr, to_end=None, to_begin=None)

Source from the content-addressed store, hash-verified

1149#####--------------------------------------------------------------------------
1150
1151def ediff1d(arr, to_end=None, to_begin=None):
1152 """
1153 Compute the differences between consecutive elements of an array.
1154
1155 This function is the equivalent of `numpy.ediff1d` that takes masked
1156 values into account, see `numpy.ediff1d` for details.
1157
1158 See Also
1159 --------
1160 numpy.ediff1d : Equivalent function for ndarrays.
1161
1162 """
1163 arr = ma.asanyarray(arr).flat
1164 ed = arr[1:] - arr[:-1]
1165 arrays = [ed]
1166 #
1167 if to_begin is not None:
1168 arrays.insert(0, to_begin)
1169 if to_end is not None:
1170 arrays.append(to_end)
1171 #
1172 if len(arrays) != 1:
1173 # We'll save ourselves a copy of a potentially large array in the common
1174 # case where neither to_begin or to_end was given.
1175 ed = hstack(arrays)
1176 #
1177 return ed
1178
1179
1180def 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