Return True if values of an array are uniformly spaced and sorted. >>> is_uniform_spaced(range(5)) True >>> is_uniform_spaced([-4, 0, 100]) False kwargs are additional arguments to ``np.isclose``
(arr, **kwargs)
| 797 | |
| 798 | |
| 799 | def is_uniform_spaced(arr, **kwargs) -> bool: |
| 800 | """Return True if values of an array are uniformly spaced and sorted. |
| 801 | |
| 802 | >>> is_uniform_spaced(range(5)) |
| 803 | True |
| 804 | >>> is_uniform_spaced([-4, 0, 100]) |
| 805 | False |
| 806 | |
| 807 | kwargs are additional arguments to ``np.isclose`` |
| 808 | """ |
| 809 | arr = np.array(arr, dtype=float) |
| 810 | diffs = np.diff(arr) |
| 811 | return bool(np.isclose(diffs.min(), diffs.max(), **kwargs)) |
| 812 | |
| 813 | |
| 814 | def hashable(v: Any) -> TypeGuard[Hashable]: |