Last active
August 29, 2015 14:09
-
-
Save alexland/e0283b72fe4985460cba to your computer and use it in GitHub Desktop.
calculating max diff for a 1D sequence
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
def fnx(arr): | |
''' | |
pass in: NumPy 1d array | |
returns: 3-tuple (idx_min_val, idx_max_val, max_diff) | |
''' | |
arr = arr.reshape(-1, 1) | |
arr_diff = arr.T - arr | |
idx = NP.unravel_index(arr_diff.argmax(), arr_diff.shape) | |
return (idx[0], idx[1], arr_diff[idx]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment