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)
| 1149 | #####-------------------------------------------------------------------------- |
| 1150 | |
| 1151 | def 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 | |
| 1180 | def unique(ar1, return_index=False, return_inverse=False): |