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)
| 1227 | #####-------------------------------------------------------------------------- |
| 1228 | |
| 1229 | def 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 | |
| 1267 | def unique(ar1, return_index=False, return_inverse=False): |
searching dependent graphs…