arraysnumpyintervalsspacing

How to get the spacing of an evenly spaced numpy array?


I have a numpy array array([1, 2, 3, 4, 5, 6, 7, 8, 9]), how do I get its spacing which is 1?


Solution

  • Note that Numpy array has not any attribute like spacing.

    But if you know that the distances between all elements are the same, it is enough to compute the distance between any pair of consecutive elements, e.g.:

    dist = arr[1] - arr[0]
    

    In your case it is just 1.