Skip to content

Instantly share code, notes, and snippets.

@alexland
Last active August 29, 2015 14:09
Show Gist options
  • Save alexland/e0283b72fe4985460cba to your computer and use it in GitHub Desktop.
Save alexland/e0283b72fe4985460cba to your computer and use it in GitHub Desktop.
calculating max diff for a 1D sequence
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