Created
May 17, 2020 04:19
-
-
Save tlancon/b8a8546ba9476135822e27d310233cb9 to your computer and use it in GitHub Desktop.
Calculate the distance between X, Y points saved arrays using NumPy's diff() function without a loop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
x = np.array([0, 1, 2, 3, 4, 5]) | |
y = np.array([4, 5, 6, 7, 8, 9]) | |
displacement = np.sqrt(np.diff(x, prepend=x[0])**2 + np.diff(y, prepend=y[0])**2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment